#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,m;
cin >> n >> m;
vector<pair<int,int>> a;
for(int i=0;i<m;i++){
int k;
cin >> k;
int b[k];
for(int j=0;j<k;j++){
cin >> b[j];
}
for(int j=1;j<k;j++){
b[j]+=b[j-1];
}
pair<int,int> p={1,n-b[k-1]};
for(int j=0;j<k;j++){
pair<int,int> cur={b[j]+1,n-(b[k-1]-b[j])};
if(cur.first>p.second+1){
a.push_back({p.second+1,cur.first-1});
}
p=cur;
}
}
sort(a.begin(),a.end());
int res=0;
if(a.size()>0){
pair<int,int> p=a[0];
for(auto x:a){
if(x.first>p.second){
res+=(p.second-p.first+1);
p=x;
}
else{
p.second=max(p.second,x.second);
}
}
res+=(p.second-p.first+1);
}
cout << res << "\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}