#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <regex>
#include <random>
#include <iomanip>
#pragma comment(linker, "/STACK:360777216")

using LL = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pii pair<int,int> 
#define vi vector<int>
#define vll vector<LL>
#define vvll vector<vector<LL>>
#define vpii vector<pii>
#define vvi vector<vector<int>>
#define forn(it,from,to) for(int (it)=from; (it)<to; (it)++)
const int  INF = 2 * 1000 * 1000 * 1000;
LL MOD = 1e9 + 7;
LL LINF = (LL)4e18;
double EPS = 1e-7;

using namespace std;


vvi users;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(10);

	LL n, m, ki;

	cin >> n >> m;
	users.resize(m);
	forn(i, 0, m)
	{
		cin >> ki;
		users[i].resize(ki);
		forn(j, 0, ki) cin >> users[i][j];
	}

	LL ans = 0;

	forn(i, 0, m)
	{
		forn(j, i + 1, m)
		{
			int cnt = 0;
			forn(k, 0, min(users[i].size(), users[j].size()))
			{
				if (cnt && users[i][k] == users[j][k]) cnt++;
				else if (!cnt && users[i][k] == users[j][k])
				{
					if (k != 0) ans++;
					cnt++;
				}
				else if (cnt && users[i][k] != users[j][k])
				{
					ans++;
					cnt = 0;
				}
			}
			if (cnt) ans++;
		}
	}

	cout << ans << endl;

	return 0;
}
