#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+555;
int n,m,a,b;
vector<int>V[maxn];
vector<int>V2;
int dis(int f,int t,int s) {
	int ret2=s-f;
	if(ret2<0)ret2+=n;
	int ret=t-s;
	if(ret<0)ret+=n;
	return ret+ret2;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
//	int mx=0;
	for(int i=0; i<m; i++)cin>>a>>b,V[a].push_back(b);
///	for(int i=1; i<=n; i++)mx=max(mx,(int)V[i].size());
//	for(int i=1; i<=n; i++)if((int)V[i].size()==mx)V2.push_back(i);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			sort(V[j].begin(),V[j].end(),[&](int o1,int o2) {
				return dis(i,o1,j)<dis(i,o2,j);
			});
		}
		int ans=0;
		for(int j=1; j<=n; j++)if(!V[j].empty())ans=max(ans,((int)V[j].size()-1)*n+dis(i,V[j][0],j));
		cout<<ans<<' ';
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5000+555;
vector<int>V[maxn];
vector<int>V2;
int n,m,a,b;
inline int dis(int f,int t,int s) {
	int ret2=s-f;
	if(ret2<0)ret2+=n;
	int ret=t-s;
	if(ret<0)ret+=n;
	return ret+ret2;
}
int main() {
	int mx=0;
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++)scanf("%d%d",&a,&b),V[a].push_back(b);
	for(int i=1; i<=n; i++)mx=max(mx,(int)V[i].size());
	for(int i=1; i<=n; i++)if((int)V[i].size()>=mx-1&&!V[i].empty())V2.push_back(i);
	for(int i=1; i<=n; i++) {
		int ans=0;
		for(int j:V2){
			int p=0x7FFFFFFF;
			for(auto k:V[j])p=min(p,((int)V[j].size()-1)*n+dis(i,k,j));
			ans=max(ans,p);
		}
		printf("%d ",ans);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> v(n);
   for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      // v[x].push_back(y);
      if (y > x) v[x].push_back(abs(x - y));
      else v[x].push_back(n - abs(x - y));
   }
   for (int i = 0; i < n; ++i) {
      sort(v[i].begin(), v[i].end());
   }
   int mx = 0;
   for (int i = 0; i < n; ++i) {
      mx = max(mx, (int)v[i].size());
   }
   vector<vector<int>> c(n);
   int tt = 0;
   for (int i = 0; i < n; ++i) {
      if (v[i].size() == mx) {
         c[i].push_back(v[i][0]);
         c[i].push_back(v[i][1]);
         ++tt, ++tt;
      }
      else if (!v[i].empty() and v[i].size() == mx - 1) {
         c[i].push_back(v[i][0]);
         ++tt;
      }
   }
   int res = max(0, (mx - 2)*n);
   priority_queue<int> q;
   for (int i = 0; i < n; ++i) {
      vector<vector<int>> t = c;
      int k = 0, j = i;
      while (k < tt) {
         if (!t[j % n].empty()) {
            int u = t[j % n].back();
            t[j % n].pop_back();
            q.push(u + j);
            // if (u > j) q.push(u + n*(j/n));
            // else q.push(u + n*(j/n + 1));
         }
         while (!q.empty() and j >= q.top()) {
            q.pop();
            ++k;
         }
         if (k < tt) ++j;
      }
      cout << j - i + res << ' ';
   }
   // for (int i = 0; i < n; ++i) {
   //    vector<vector<int>> t = v;
   //    int k = 0, j = i;
   //    while (k < m) {
   //       if (!t[j % n].empty()) {
   //          int u = t[j % n].back();
   //          t[j % n].pop_back();
   //          q.push(u + j);
   //          // if (u > j) q.push(u + n*(j/n));
   //          // else q.push(u + n*(j/n + 1));
   //       }
   //       while (!q.empty() and j >= q.top()) {
   //          q.pop();
   //          ++k;
   //       }
   //       if (k < m) ++j;
   //    }
   //    cout << j - i << ' ';
   // }
   cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;

int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> v(n);
   for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      if (y > x) v[x].push_back(abs(x - y));
      else v[x].push_back(n - abs(x - y));
   }
   for (int i = 0; i < n; ++i) {
      sort(v[i].begin(), v[i].end());
   }
   int mx = 0;
   for (int i = 0; i < n; ++i) {
      mx = max(mx, (int)v[i].size());
   }
   for (int i = 0; i < n; ++i) {
      int k = i;
      for (int j = 0; j < n; ++j) {
         int p = (i + j) % n;
         if (v[p].size() == mx) {
            k = max(k, i + j + v[p][0]);
         }
         else if (!v[p].empty() and v[p].size() == mx - 1) {
            k = max(k, i + j - n + v[p][0]);
         }
      }
      cout << n*(mx - 1) + k - i << ' ';
   }
   cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;

int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> v(n);
   for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      // v[x].push_back(y);
      if (y > x) v[x].push_back(abs(x - y));
      else v[x].push_back(n - abs(x - y));
   }
   for (int i = 0; i < n; ++i) {
      sort(v[i].begin(), v[i].end());
   }
   int mx = 0;
   for (int i = 0; i < n; ++i) {
      mx = max(mx, (int)v[i].size());
   }
   vector<vector<int>> c(n);
   int tt = 0;
   for (int i = 0; i < n; ++i) {
      if (v[i].size() == mx) {
         c[i].push_back(v[i][0]);
         c[i].push_back(v[i][1]);
         ++tt, ++tt;
      }
      else if (!v[i].empty() and v[i].size() == mx - 1) {
         c[i].push_back(v[i][0]);
         ++tt;
      }
   }
   int res = (mx - 2)*n;
   priority_queue<int> q;
   for (int i = 0; i < n; ++i) {
      vector<vector<int>> t = c;
      int k = 0, j = i;
      while (k < tt) {
         if (!t[j % n].empty()) {
            int u = t[j % n].back();
            t[j % n].pop_back();
            q.push(u + j);
            // if (u > j) q.push(u + n*(j/n));
            // else q.push(u + n*(j/n + 1));
         }
         while (!q.empty() and j >= q.top()) {
            q.pop();
            ++k;
         }
         if (k < tt) ++j;
      }
      cout << j - i + res << ' ';
   }
   // for (int i = 0; i < n; ++i) {
   //    vector<vector<int>> t = v;
   //    int k = 0, j = i;
   //    while (k < m) {
   //       if (!t[j % n].empty()) {
   //          int u = t[j % n].back();
   //          t[j % n].pop_back();
   //          q.push(u + j);
   //          // if (u > j) q.push(u + n*(j/n));
   //          // else q.push(u + n*(j/n + 1));
   //       }
   //       while (!q.empty() and j >= q.top()) {
   //          q.pop();
   //          ++k;
   //       }
   //       if (k < m) ++j;
   //    }
   //    cout << j - i << ' ';
   // }
   cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;

int main() {
   ios::sync_with_stdio(0);
   cin.tie(0);
   int n, m;
   cin >> n >> m;
   vector<vector<int>> v(n);
   for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      // v[x].push_back(y);
      if (y > x) v[x].push_back(abs(x - y));
      else v[x].push_back(n - abs(x - y));
   }
   for (int i = 0; i < n; ++i) {
      sort(v[i].begin(), v[i].end());
   }
   int mx = 0;
   for (int i = 0; i < n; ++i) {
      mx = max(mx, (int)v[i].size());
   }
   vector<vector<int>> c(n);
   int tt = 0;
   for (int i = 0; i < n; ++i) {
      if (v[i].size() == mx) {
         c[i].push_back(v[i][0]);
         ++tt;
      }
   }
   int res = (mx - 1)*n;
   priority_queue<int> q;
   for (int i = 0; i < n; ++i) {
      vector<vector<int>> t = c;
      int k = 0, j = i;
      while (k < tt) {
         if (!t[j % n].empty()) {
            int u = t[j % n].back();
            t[j % n].pop_back();
            q.push(u + j);
            // if (u > j) q.push(u + n*(j/n));
            // else q.push(u + n*(j/n + 1));
         }
         while (!q.empty() and j >= q.top()) {
            q.pop();
            ++k;
         }
         if (k < tt) ++j;
      }
      cout << j - i + res << ' ';
   }
   // for (int i = 0; i < n; ++i) {
   //    vector<vector<int>> t = v;
   //    int k = 0, j = i;
   //    while (k < m) {
   //       if (!t[j % n].empty()) {
   //          int u = t[j % n].back();
   //          t[j % n].pop_back();
   //          q.push(u + j);
   //          // if (u > j) q.push(u + n*(j/n));
   //          // else q.push(u + n*(j/n + 1));
   //       }
   //       while (!q.empty() and j >= q.top()) {
   //          q.pop();
   //          ++k;
   //       }
   //       if (k < m) ++j;
   //    }
   //    cout << j - i << ' ';
   // }
   cout << '\n';
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < int > v[5010];
int urm[5010];

int arb[20100];

void update (int nod , int st , int dr , int pos , int val){
    if (st == dr){
        arb[nod] = val;
        return;
    }

    int mij = st + dr;
    mij /= 2;

    if (pos <= mij){
        update (nod*2 , st , mij , pos , val);
    }
    else {
        update (nod*2+1 , mij+1 , dr , pos , val);
    }
    arb[nod] = max(arb[nod*2] , arb[nod*2+1]);
}

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    int n , m;
    cin>>n>>m;

    for (int i=1; i<=m; i++){
        int a , b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    int MAX = 0;

    for (int i=1; i<=n; i++){
        MAX = max(MAX , (int)v[i].size());
    }

    int last = 0;

    for (int i=1; i<=n; i++){
        if (v[i].size() < MAX-1){
            continue;
        }
        int MIN = 1e9;
        int bef = 1e9;
        for (auto &x : v[i]){
            if (x < i){
                if (MIN > x + n - i){
                    bef = MIN;
                    MIN = x+n-i;
                }
                else if(bef > x + n -i){
                    bef = x+n-i;
                }
            }
            else {
                if (MIN > x-i){
                    bef = MIN;
                    MIN = x-i;
                }
                else if(bef > x-i){
                    bef = x-i;
                }
            }
        }
        if (v[i].size() == MAX && MAX > 1){
            urm[i] = MIN;
            last = max(last , i + bef - n);
        }
        else {
            last = max(last , i+MIN-n);
        }
    }

    /*for (int i=1; i<=n; i++){
        cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    MAX--;

    for (int i=1; i<=n; i++){
        if (urm[i]){
            update(1 , 1 , n , i , i + urm[i]);
        }
    }
    cout<<MAX * n + /*arb[1]*/ max(arb[1] , last) - 1<<" ";
    for (int i=2; i<=n; i++){
        if (urm[i-1]){
            update(1 , 1 , n , i-1 , n+i-1+urm[i-1]);
        }
        cout<<MAX * n + /*arb[1]*/ max(last , arb[1]) - i<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < long long  > v[5010];
long long  urm[5010];

long long  arb[20100];

void update (long long  nod , long long  st , long long  dr , long long  pos , long long  val){
    if (st == dr){
        arb[nod] = val;
        return;
    }

    long long  mij = st + dr;
    mij /= 2;

    if (pos <= mij){
        update (nod*2 , st , mij , pos , val);
    }
    else {
        update (nod*2+1 , mij+1 , dr , pos , val);
    }
    arb[nod] = max(arb[nod*2] , arb[nod*2+1]);
}

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    long long  n , m;
    cin>>n>>m;

    for (long long  i=1; i<=m; i++){
        long long  a , b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    long long  MAX = 0;

    for (long long  i=1; i<=n; i++){
        MAX = max(MAX , (long long )v[i].size());
    }

    for (long long  i=1; i<=n; i++){
        if (v[i].size() < MAX){
            continue;
        }
        long long  MIN = 1e9;
        for (auto &x : v[i]){
            if (x < i){
                MIN = min(MIN , x + n - i);
            }
            else {
                MIN = min(MIN , x - i);
            }
        }
        urm[i] = MIN;
    }

    /*for (long long  i=1; i<=n; i++){
        cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    MAX--;

    for (long long  i=1; i<=n; i++){
        if (urm[i]){
            update(1 , 1 , n , i , i + urm[i]);
        }
    }
    cout<<MAX * n + arb[1] - 1<<" ";
    for (long long  i=2; i<=n; i++){
        if (urm[i-1]){
            update(1 , 1 , n , i-1 , n+i-1+urm[i-1]);
        }
        cout<<MAX * n + arb[1] - i<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < int > gr[5050];
int urm[5050];

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    int n , m;
    cin>>n>>m;

    for (int i=1; i<=m; i++){
    	int a , b;
    	cin>>a>>b;
    	gr[a].push_back(b);
    }

    for (int i=1; i<=n; i++){
    	if (!gr[i].empty()){
    		urm[i] = 1e9;
    	}
    	for (auto &x : gr[i]){
    		if (x < i){
    			urm[i] = min(urm[i] , x + n - i);
    		}
    		else {
    			urm[i] = min(urm[i] , x - i);
    		}
    	}
    }

    /*for (int i=1; i<=n; i++){
    	cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    for (int i=1; i<=n; i++){
    	int MAX = 0;
    	for (int j=1; j<=n; j++){
    		if (!urm[j]){
    			continue;
    		}
    		if (j < i){
    			MAX = max(MAX , ((int)gr[j].size() - 1) * n + j + urm[j] + n - i);
    		}
    		else {
    			MAX = max(MAX , ((int)gr[j].size() - 1) * n + j + urm[j] 	 - i);
    		}
    	}
    	cout<<MAX<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < long long  > v[5010];
long long  urm[5010];

long long  arb[20100];

void update (long long  nod , long long  st , long long  dr , long long  pos , long long  val){
    if (st == dr){
        arb[nod] = val;
        return;
    }

    long long  mij = st + dr;
    mij /= 2;

    if (pos <= mij){
        update (nod*2 , st , mij , pos , val);
    }
    else {
        update (nod*2+1 , mij+1 , dr , pos , val);
    }
    arb[nod] = max(arb[nod*2] , arb[nod*2+1]);
}

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    long long  n , m;
    cin>>n>>m;

    for (long long  i=1; i<=m; i++){
        long long  a , b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    long long  MAX = 0;

    for (long long  i=1; i<=n; i++){
        MAX = max(MAX , (long long )v[i].size());
    }

    long long  last = 0;

    for (long long  i=1; i<=n; i++){
        if (v[i].size() < MAX-1){
            continue;
        }
        long long  MIN = 1e9;
        long long  bef = 1e9;
        for (auto &x : v[i]){
            if (x < i){
                if (MIN > x + n - i){
                    bef = MIN;
                    MIN = x+n-i;
                }
                else if(bef > x + n -i){
                    bef = x+n-i;
                }
            }
            else {
                if (MIN > x-i){
                    bef = MIN;
                    MIN = x-i;
                }
                else if(bef > x-i){
                    bef = x-i;
                }
            }
        }
        if (v[i].size() == MAX){
            urm[i] = MIN;
            if (MAX > 1){
                last = max(last , i + bef - n);
            }
        }
        else if (MAX > 1){
            last = max(last , i+MIN-n);
        }
    }

    /*for (long long  i=1; i<=n; i++){
        cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    MAX--;

    for (long long  i=1; i<=n; i++){
        if (urm[i]){
            update(1 , 1 , n , i , i + urm[i]);
        }
    }
    cout<<MAX * n + /*arb[1]*/ max(arb[1] , last) - 1<<" ";
    for (long long  i=2; i<=n; i++){
        if (urm[i-1]){
            update(1 , 1 , n , i-1 , n+i-1+urm[i-1]);
        }
        cout<<MAX * n + /*arb[1]*/ max(last , arb[1]) - i<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < int > v[5010];
int urm[5010];

int arb[20100];

void update (int nod , int st , int dr , int pos , int val){
    if (st == dr){
        arb[nod] = val;
        return;
    }

    int mij = st + dr;
    mij /= 2;

    if (pos <= mij){
        update (nod*2 , st , mij , pos , val);
    }
    else {
        update (nod*2+1 , mij+1 , dr , pos , val);
    }
    arb[nod] = max(arb[nod*2] , arb[nod*2+1]);
}

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    int n , m;
    cin>>n>>m;

    for (int i=1; i<=m; i++){
        int a , b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    int MAX = 0;

    for (int i=1; i<=n; i++){
        MAX = max(MAX , (int)v[i].size());
    }

    for (int i=1; i<=n; i++){
        if (v[i].size() < MAX){
            continue;
        }
        int MIN = 1e9;
        for (auto &x : v[i]){
            if (x < i){
                MIN = min(MIN , x + n - i);
            }
            else {
                MIN = min(MIN , x - i);
            }
        }
        urm[i] = MIN;
    }

    /*for (int i=1; i<=n; i++){
        cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    MAX--;

    for (int i=1; i<=n; i++){
        if (urm[i]){
            update(1 , 1 , n , i , i + urm[i]);
        }
    }
    cout<<MAX * n + arb[1] - 1<<" ";
    for (int i=2; i<=n; i++){
        if (urm[i-1]){
            update(1 , 1 , n , i-1 , n+i-1+urm[i-1]);
        }
        cout<<MAX * n + arb[1] - i<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < int > v[5010];
int urm[5010];

int arb[20100];

void update (int nod , int st , int dr , int pos , int val){
    if (st == dr){
        arb[nod] = val;
        return;
    }

    int mij = st + dr;
    mij /= 2;

    if (pos <= mij){
        update (nod*2 , st , mij , pos , val);
    }
    else {
        update (nod*2+1 , mij+1 , dr , pos , val);
    }
    arb[nod] = max(arb[nod*2] , arb[nod*2+1]);
}

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    int n , m;
    cin>>n>>m;

    for (int i=1; i<=m; i++){
        int a , b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    int MAX = 0;

    for (int i=1; i<=n; i++){
        MAX = max(MAX , (int)v[i].size());
    }

    int last = 0;

    for (int i=1; i<=n; i++){
        if (v[i].size() < MAX-1){
            continue;
        }
        int MIN = 1e9;
        int bef = 1e9;
        for (auto &x : v[i]){
            if (x < i){
                if (MIN > x + n - i){
                    bef = MIN;
                    MIN = x+n-i;
                }
                else if(bef > x + n -i){
                    bef = x+n-i;
                }
            }
            else {
                if (MIN > x-i){
                    bef = MIN;
                    MIN = x-i;
                }
                else if(bef > x-i){
                    bef = x-i;
                }
            }
        }
        if (v[i].size() == MAX){
            urm[i] = MIN;
            if (MAX > 1){
                last = max(last , i + bef - n);
            }
        }
        else if (MAX > 1){
            last = max(last , i+MIN-n);
        }
    }

    /*for (int i=1; i<=n; i++){
        cout<<urm[i]<<" ";
    }
    cout<<'\n';*/

    MAX--;

    for (int i=1; i<=n; i++){
        if (urm[i]){
            update(1 , 1 , n , i , i + urm[i]);
        }
    }
    cout<<MAX * n + /*arb[1]*/ max(arb[1] , last) - 1<<" ";
    for (int i=2; i<=n; i++){
        if (urm[i-1]){
            update(1 , 1 , n , i-1 , n+i-1+urm[i-1]);
        }
        cout<<MAX * n + /*arb[1]*/ max(last , arb[1]) - i<<" ";
    }

    return 0;
}


//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

#include <iostream>
//#include <fstream>
//ifstream cin (".in");ofstream cout (".out");

vector < int > gr[5050];
int urm[5050];

int main() {

    freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<setprecision(10)<<fixed;

    int n , m;
    cin>>n>>m;

    for (int i=1; i<=m; i++){
    	int a , b;
    	cin>>a>>b;
    	gr[a].push_back(b);
    }

    for (int i=1; i<=n; i++){
    	if (!gr[i].empty()){
    		urm[i] = 1e9;
    	}
    	for (auto &x : gr[i]){
    		if (x < i){
    			urm[i] = min(urm[i] , x + n - i);
    		}
    		else {
    			urm[i] = min(urm[i] , x - i);
    		}
    	}
    }

    for (int i=1; i<=n; i++){
    	cout<<urm[i]<<" ";
    }
    cout<<'\n';

    for (int i=1; i<=n; i++){
    	int MAX = 0;
    	for (int j=1; j<=n; j++){
    		if (!urm[j]){
    			continue;
    		}
    		if (j < i){
    			MAX = max(MAX , ((int)gr[j].size() - 1) * n + j + urm[j] + n - i);
    		}
    		else {
    			MAX = max(MAX , ((int)gr[j].size() - 1) * n + j + urm[j] 	 - i);
    		}
    	}
    	cout<<MAX<<" ";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
const int MAXN = 5005, MAXM = 20005;
vector<int> candies[MAXN];
int closest[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(closest, -1, sizeof closest);
    int N, M; cin >> N >> M;
    for (int i=0; i<M; i++){
        int a, b; cin >> a >> b; a--, b--;
        candies[a].push_back(b);
    }
    int maxsize = 0;
    for (int i=0; i<N; i++){
        maxsize = max(maxsize, (int) candies[i].size());
    }
    for (int i=0; i<N; i++){
        int mincost = 1e9;
        int best = 0;
        for (auto j:candies[i]){
            int curcost = (j-i+N)%N;
            if (curcost < mincost){
                mincost = curcost;
                best = j;
            }
        }
        closest[i] = best;
    }
    for (int i=0; i<N; i++){
        int rem = 0;
        for (int j=0; j<N; j++){
            int cost = (j-i+N)%N;
            cost += (candies[j].size()-1)*N;
            cost += (closest[j]-j+N)%N;
            rem = max(cost, rem);
        }
        cout << rem << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
const int MAXN = 5005, MAXM = 20005;
vector<int> candies[MAXN];
int closest[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(closest, -1, sizeof closest);
    int N, M; cin >> N >> M;
    for (int i=0; i<M; i++){
        int a, b; cin >> a >> b; a--, b--;
        candies[a].push_back(b);
    }
    for (int i=0; i<N; i++){
        int mincost = 1e9;
        int best = 0;
        for (auto j:candies[i]){
            int curcost = (j-i+N)%N;
            if (curcost < mincost){
                mincost = curcost;
                best = j;
            }
        }
        closest[i] = best;
    }
    for (int i=0; i<N; i++){
        int rem = 0;
        for (int j=0; j<N; j++){
            if (candies[j].empty()) continue;
            int cost = (j-i+N)%N;
            cost += (candies[j].size()-1)*N;
            cost += (closest[j]-j+N)%N;
            rem = max(cost, rem);
        }
        cout << rem << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
const int MAXN = 5005, MAXM = 20005;
vector<int> candies[MAXN];
int closest[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(closest, -1, sizeof closest);
    int N, M; cin >> N >> M;
    for (int i=0; i<M; i++){
        int a, b; cin >> a >> b; a--, b--;
        candies[a].push_back(b);
    }
    int maxsize = 0;
    for (int i=0; i<N; i++){
        maxsize = max(maxsize, (int) candies[i].size());
    }
    for (int i=0; i<N; i++){
        if (candies[i].size() == maxsize){
            int mincost = 1e9;
            int best = 0;
            for (auto j:candies[i]){
                int curcost = (j-i+N)%N;
                if (curcost < mincost){
                    mincost = curcost;
                    best = j;
                }
            }
            closest[i] = best;
        }
        //cout << closest[i] << " ";
    }
    //cout << "\n";
    for (int i=0; i<N; i++){
        int rem = 0;
        for (int j=0; j<N; j++){
            if (closest[j] == -1) continue;
            int cost = (j-i+N)%N;
            cost += (maxsize-1)*N;
            cost += (closest[j]-j+N)%N;
            rem = max(cost, rem);
        }
        cout << rem << " ";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
const int MAXN = 5005, MAXM = 20005;
vector<int> candies[MAXN];
int closest[MAXN];

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(closest, -1, sizeof closest);
    int N, M; cin >> N >> M;
    for (int i=0; i<M; i++){
        int a, b; cin >> a >> b; a--, b--;
        candies[a].push_back(b);
    }
    int maxsize = 0;
    for (int i=0; i<N; i++){
        maxsize = max(maxsize, (int) candies[i].size());
    }
    for (int i=0; i<N; i++){
        if (candies[i].size() == maxsize){
            int mincost = 1e9;
            int best = 0;
            for (auto j:candies[i]){
                int curcost = (j-i+N)%N;
                if (curcost < mincost){
                    mincost = curcost;
                    best = j;
                }
            }
            closest[i] = best;
        }
        //out << closest[i] << " ";
    }
    //cout << "\n";
    for (int i=0; i<N; i++){
        int rem = 0;
        for (int j=0; j<N; j++){
            if (closest[j] == -1) continue;
            int residue = (closest[j] - i + N)%N;
            if (residue == 0) residue = N;
            rem = max(rem, residue);
        }
        cout << rem + (maxsize-1)*N << " ";
    }
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n+1;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)
    {
        int r=0;
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m)r=max(r,mini[i0]-d(i0,i));
        }
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)
    {
        int r=0;
        cnt[i]--;
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        cnt[i]++;
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)
    {
        int r=0,m=0;
        cnt[i]--;
        for(i0=1;i0<=n;i0++)m=max(m,cnt[i0]);
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        cnt[i]++;
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d0(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int d(int x,int y){return (x<y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)
    {
        int r=0;
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d0(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n+1;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)
    {
        int r=0;
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<=y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)
    {
        int r=0,m=0;
        cnt[i]--;
        for(i0=1;i0<=n;i0++)m=max(m,cnt[i]);
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        cnt[i]++;
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
vector<int>v;
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n+1;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],(x<=y)?(y-x):(y-x+n));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)if(cnt[i]==m)v.push_back(i);
    for(i=1;i<=n;i++)
    {
        int r=0;
        for(int i0:v)r=max(r,((i<=i0)?(i0-i):(i0-i+n))+mini[i0]);
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,i0,n,m,cnt[5005],mini[5005];
int d(int x,int y){return (x<y)?(y-x):(y-x+n);}
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)mini[i]=n;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        cnt[x]++;
        mini[x]=min(mini[x],d(x,y));
    }
    for(i=1;i<=n;i++)m=max(m,cnt[i]);
    for(i=1;i<=n;i++)
    {
        int r=0;
        for(i0=1;i0<=n;i0++)
        {
            if(cnt[i0]==m)r=max(r,d(i,i0)+mini[i0]);
            if(cnt[i0]+1==m&&cnt[i0])r=max(r,mini[i0]-d(i0,i));
        }
        printf("%lld ",(long long)(m-1)*n+r);
    }
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[50001];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int main(){
	fastread;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].pb(v);
	}

	for(int i = 0;i<n;i++){
		cur = i;
		sort(g[i].begin(), g[i].end(),cmp);
	}

	int mx = 0;
	for(int i=0;i<n;i++){
		mx = max(mx, (int)g[i].size());
	}
	int ans = (mx-1)*n;

	for(int i=0;i<n;i++){
		int tmp = 0;
		for(int j=0;j<n;j++){
			if(g[j].size() == mx){
				// cout<<i<<" "<<j<<" "<<g[j].back()<<endl;
				// cout<<i<<" "<<(j-i+n)%n<<" "<<(g[j].back()-j+n)%n<<endl;
				tmp = max(tmp, (j-i+n)%n + (g[j].back()-j+n)%n);
			}
		}
		cout<<ans+tmp<<" ";
	}

	cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[50001];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int main(){
	fastread;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}

	for(int i = 1;i<=n;i++){
		cur = i;
		sort(g[i].begin(), g[i].end(),cmp);
	}

	int cost = 0;

	for(int i=1;i<=n;i++){
		int ans = 0;
		int j = i;
		int k = m;
		vector<int> pt(n+1);
		vector<int> cart(n+1);
		int mx = 0;
		for(int j=1;j<=n;j++){
			mx = max(mx,(int)g[j].size());
		}
		ans = (mx-1)*n;

		for(int j=1;j<=n;j++){
			if(mx-1 > g[j].size()){
				k -= (int)g[j].size();
			}else{
				k -= (mx-1);
			}
			pt[j] = mx-1;
		}
		while(k){
			k-=cart[j];
			cart[j] = 0;
			if(k==0) break;
			if(pt[j] < g[j].size()){
				cart[g[j][pt[j]]]+=1;
				pt[j]++;
			}
			ans++;
			j++;
			if(j>n) j =1 ;
		}
		cout<<ans<<" ";
	}cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[50001];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int main(){
	fastread;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].pb(v);
	}

	for(int i = 0;i<n;i++){
		cur = i;
		sort(g[i].begin(), g[i].end(),cmp);
	}

	for(int i=0;i<n;i++){
		int tmp = 0;
		for(int j=0;j<n;j++){
			if(g[j].size()==0)continue;
			tmp = max(tmp,((int)g[j].size()-1)*n + (j-i+n)%n + (g[j].back()-j+n)%n);
		}
		cout<<tmp<<" ";
	}

	cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[50001];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int main(){
	fastread;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}

	for(int i = 1;i<=n;i++){
		cur = i;
		sort(g[i].begin(), g[i].end(),cmp);
	}

	int cost = 0;

	for(int i=1;i<=n;i++){
		int ans = 0;
		int j = i;
		int k = m;
		vector<int> pt(n+1);
		vector<int> cart(n+1);
		int mx = 0;
		for(int j=1;j<=n;j++){
			mx = max(mx,(int)g[j].size());
		}
		ans = (mx-1)*n;

		for(int j=1;j<=n;j++){
			k -= (int)g[j].size();
			if(g[j].size() > mx-1){
				k += 1;
			}
			pt[j] = mx-1;
		}
		while(k){
			k-=cart[j];
			cart[j] = 0;
			if(k==0) break;
			if(pt[j] < g[j].size()){
				cart[g[j][pt[j]]]+=1;
				pt[j]++;
			}
			ans++;
			j++;
			if(j>n) j =1 ;
		}
		cout<<ans<<" ";
	}cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

vector<int> g[50001];

int cur;
	int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int main(){
	fastread;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
	}

	for(int i = 1;i<=n;i++){
		cur = i;
		sort(g[i].begin(), g[i].end(),cmp);
	}

	// for(int i=1;i<=n;i++){
	// 	for(int j=0;j<g[i].size();j++){
	// 		cout<<g[i][j]<<" ";

	// 	}cout<<endl;
	// }

	int cost = 0;

	for(int i=1;i<=n;i++){
		int ans = 0;
		int j = i;
		int k = m;
		vector<int> pt(n+1);
		vector<int> cart(n+1);
		while(k){
			k-=cart[j];
			cart[j] = 0;
			if(k==0) break;
			if(pt[j] < g[j].size()){
				cart[g[j][pt[j]]]+=1;
				pt[j]++;
			}
			ans++;
			j++;
			if(j>n) j =1 ;
		}
		cout<<ans<<" ";
	}cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
// #define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int g[5101][20101];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int b[5101];

int main(){
	fastread;
	cin>>n>>m;

	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u][b[u]] = v;
		b[u]++;
	}

	for(int i = 1;i<=n;i++){
		cur = i;
		sort(g[i], g[i]+b[i],cmp);
	}

	int cost = 0;

	// vector<int> cart(n+1);
	int cart[5101] = {0};
	int pt [5101] = {0};
	for(int i=1;i<=n;i++){
		int ans = 0;
		int j = i;
		int k = m;
		memset(pt,0,sizeof(pt));
		while(k){
			k-=cart[j];
			cart[j] = 0;
			if(k==0) break;
			if(pt[j] < b[j]){
				cart[g[j][pt[j]]]+=1;
				pt[j]++;
			}
			ans++;
			j++;
			if(j>n) j =1 ;
		}
		cout<<ans<<" ";
	}cout<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
// #define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

static struct IO {
	char tmp[1 << 10];

	// fast input routines
	char cur;

//#define nextChar() (cur = getc_unlocked(stdin))
//#define peekChar() (cur)
	inline char nextChar() { return cur = getc_unlocked(stdin); }
	inline char peekChar() { return cur; }

	inline operator bool() { return peekChar(); }
	inline static bool isBlank(char c) { return (c < '-' && c); }
	inline bool skipBlanks() { while (isBlank(nextChar())); return peekChar() != 0; }

	inline IO& operator >> (char & c) { c = nextChar(); return *this; }

	inline IO& operator >> (char * buf) {
		if (skipBlanks()) {
			if (peekChar()) {
				*(buf++) = peekChar();
				while (!isBlank(nextChar())) *(buf++) = peekChar();
			} *(buf++) = 0; } return *this; }

	inline IO& operator >> (string & s) {
		if (skipBlanks()) {	s.clear(); s += peekChar();
			while (!isBlank(nextChar())) s += peekChar(); }
		return *this; }

	inline IO& operator >> (double & d) { if ((*this) >> tmp) sscanf(tmp, "%lf", &d); return *this;	}

#define defineInFor(intType) \
	inline IO& operator >>(intType & n) { \
		if (skipBlanks()) { \
			int sign = +1; \
			if (peekChar() == '-') { \
				sign = -1; \
				n = nextChar() - '0'; \
			} else \
				n = peekChar() - '0'; \
			while (!isBlank(nextChar())) { \
				n += n + (n << 3) + peekChar() - 48; \
			} \
			n *= sign; \
		} \
		return *this; \
	}

defineInFor(int)
defineInFor(unsigned int)
defineInFor(long long)

	// fast output routines

//#define putChar(c) putc_unlocked((c), stdout)
	inline void putChar(char c) { putc_unlocked(c, stdout); }
	inline IO& operator << (char c) { putChar(c); return *this; }
	inline IO& operator << (const char * s) { while (*s) putChar(*s++); return *this; }

	inline IO& operator << (const string & s) { for (int i = 0; i < (int)s.size(); ++i) putChar(s[i]); return *this; }

	char * toString(double d) { sprintf(tmp, "%lf%c", d, '\0'); return tmp; }
	inline IO& operator << (double d) { return (*this) << toString(d); }

#define defineOutFor(intType) \
	inline char * toString(intType n) { \
		char * p = (tmp + 30); \
		if (n) { \
			bool isNeg = 0; \
			if (n < 0) isNeg = 1, n = -n; \
			while (n) \
				*--p = (n % 10) + '0', n /= 10; \
			if (isNeg) *--p = '-'; \
		} else *--p = '0'; \
		return p; \
	} \
	inline IO& operator << (intType n) { return (*this) << toString(n); }

defineOutFor(int)
defineOutFor(long long)

#define endl ('\n')
#define cout __io__
#define cin __io__
} __io__;

int g[5101][20101];

int cur;
int n,m;

bool cmp(int u, int v){
	if(u < cur){
		u+= n;
	}
	if(v < cur){
		v += n;
	}
	return abs(u-cur) > abs(v-cur);
}

int b[5101];

int main(){
	cin>>n>>m;

	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u][b[u]] = v;
		b[u]++;
	}

	for(int i = 1;i<=n;i++){
		cur = i;
		sort(g[i], g[i]+b[i],cmp);
	}

	int cost = 0;

	// vector<int> cart(n+1);
	int cart[5101] = {0};
	int pt [5101] = {0};
	for(int i=1;i<=n;i++){
		int ans = 0;
		int j = i;
		int k = m;
		memset(pt,0,sizeof(pt));
		while(k){
			k-=cart[j];
			cart[j] = 0;
			if(k==0) break;
			if(pt[j] < b[j]){
				cart[g[j][pt[j]]]+=1;
				pt[j]++;
			}
			ans++;
			j++;
			if(j>n) j =1 ;
		}
		cout<<ans<<" ";
	}cout<<endl;

}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    for (int i = 1; i <= n; ++i) {
        A[i][i] = INT_MAX;
    }

    vector<pair<int,int>> C(n+1, {INT_MAX, INT_MAX});

    vector<int> D(n+1);
    fori(m) {
        int a, b; cin >> a >> b;
        D[a]++;
        //check;
        int B = b;
        if (B < a) {
            B += n;
        }
        if (B - a <= C[a].first - a) {
            C[a].second = C[a].first;
            C[a].first = b;
        }
        else if (B - a < C[a].second - a) {
            C[a].second = b;
        }

    }

    //*********************
        int circle = 0;

        for (int i = 1; i <= n; ++i) {
            if (D[i] > 2) {
                int z = D[i] - 2;
                m -= z;
                circle = max(circle, z);
            }
        }
    //****************
    for (int i = 1; i <= n; ++i) {
        if (C[i].first != INT_MAX) {
            A[i][C[i].first]++;
        }
        if (C[i].second != INT_MAX) {
            A[i][C[i].second]++;
        }
    }

    /*
    fori(m) {
        int a, b; cin >> a >> b;
        A[a][b]++;
    }
    */

    vector<vector<int>> OG = A;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        int pos = start;
        int ans = circle * n;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                int idx = INT_MAX;
                if (C[pos].second != INT_MAX && A[pos][C[pos].second] != 0) {
                    idx = C[pos].second;
                }
                else if (C[pos].first != INT_MAX && A[pos][C[pos].first] != 0) {
                    idx = C[pos].first;
                }
                else {
                    idx = pos;
                }
                //check if there any candies left
                if (A[pos][idx] != INT_MAX) {
                    A[pos][idx]--;
                    Backpack[idx]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    vector<int> Index(n+1);
    for (int i = 1; i <= n; ++i) {
        Index[i] = i-1;
        if (Index[i] < 1) {
            Index[i] += n;
        }
        A[i][i] = INT_MAX;
    }

    fori(m) {
        int a, b; cin >> a >> b;
        A[a][b]++;
    }

    vector<vector<int>> OG = A;
    vector<int> OG2 = Index;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        Index = OG2;
        int pos = start;
        int ans = 0;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                while(A[pos][Index[pos]] == 0) {
                    Index[pos]--;
                    if (Index[pos] < 1) {
                        Index[pos] += n;
                    }
                }
                //check if there any candies left
                if (A[pos][Index[pos]] != INT_MAX) {
                    A[pos][Index[pos]]--;
                    Backpack[Index[pos]]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    for (int i = 1; i <= n; ++i) {
        A[i][i] = INT_MAX;
    }

    vector<pair<int,int>> C(n+1, {INT_MAX, INT_MAX});

    vector<int> D(n+1);
    fori(m) {
        int a, b; cin >> a >> b;
        D[a]++;
        //check;
        int B = b;
        if (B < a) {
            B += n;
        }
        if (B - a <= C[a].first - a) {
            C[a].second = C[a].first;
            C[a].first = b;
        }
        else if (B - a < C[a].second - a) {
            C[a].second = b;
        }

    }

    //*********************
        int circle = 0;

        for (int i = 1; i <= n; ++i) {
            if (D[i] > 2) {
                int z = D[i] - 2;
                m -= z;
                circle = max(circle, z);
            }
        }
    //****************
    for (int i = 1; i <= n; ++i) {
        if (C[i].first != INT_MAX) {
            A[i][C[i].first]++;
        }
        if (C[i].second != INT_MAX) {
            A[i][C[i].second]++;
        }
    }

    /*
    fori(m) {
        int a, b; cin >> a >> b;
        A[a][b]++;
    }
    */

    vector<vector<int>> OG = A;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        int pos = start;
        int ans = circle * n;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                int idx = INT_MAX;
                if (C[pos].second != INT_MAX && A[pos][C[pos].second] != 0) {
                    idx = C[pos].second;
                }
                else if (C[pos].first != INT_MAX && A[pos][C[pos].first] != 0) {
                    idx = C[pos].first;
                }
                else {
                    idx = pos;
                }
                //check if there any candies left
                if (A[pos][idx] != INT_MAX && idx != pos) {
                    A[pos][idx]--;
                    Backpack[idx]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;
    vector<int> A(n, INT_MAX);
    vector<int> cnt(n, 0);
    fori(m) {
        int a, b; cin >> a >> b;
        a--; b--;
        cnt[a]++;
        int dist = b - a;
        if (dist < 0)
            dist += n;
        A[a] = min(A[a], dist);
    }

    for (int start = 0; start < n; ++start) {
        int answ = 0;
        int a = start;
        int k = 0;
        while (k != n) {
            if (cnt[a] > 0)
                answ = max(answ, (cnt[a]-1) * n + A[a] + k);
            ++a; ++k;
            if (a == n)
                a = 0;
        }
        cout << answ << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    for (int i = 1; i <= n; ++i) {
        A[i][i] = INT_MAX;
    }

    vector<pair<int,int>> C(n+1, {INT_MAX, INT_MAX});

    vector<int> D(n+1);
    fori(m) {
        int a, b; cin >> a >> b;
        D[a]++;
        //check;
        int B = b;
        if (B < a) {
            B += n;
        }
        if (B - a <= C[a].first - a) {
            C[a].second = C[a].first;
            C[a].first = b;
        }
        else if (B - a < C[a].second - a) {
            C[a].second = b;
        }

    }

    //*********************
        int circle = 0;

        for (int i = 1; i <= n; ++i) {
            if (D[i] > 2) {
                int z = D[i] - 2;
                m -= z;
                circle = max(circle, z);
            }
        }
    //****************
    for (int i = 1; i <= n; ++i) {
        if (C[i].first != INT_MAX) {
            A[i][C[i].first]++;
        }
        if (C[i].second != INT_MAX) {
            A[i][C[i].second]++;
        }
    }

    /*
    fori(m) {
        int a, b; cin >> a >> b;
        A[a][b]++;
    }
    */

    vector<vector<int>> OG = A;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        int pos = start;
        int ans = circle * n;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                int idx = INT_MAX;
                if (C[pos].second != INT_MAX && A[pos][C[pos].second] != 0) {
                    idx = C[pos].second;
                }
                else if (C[pos].first != INT_MAX && A[pos][C[pos].first] != 0) {
                    idx = C[pos].first;
                }
                else {
                    idx = pos;
                }
                //check if there any candies left
                if (A[pos][idx] != INT_MAX || idx == pos) {
                    A[pos][idx]--;
                    Backpack[idx]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    for (int i = 1; i <= n; ++i) {
        A[i][i] = INT_MAX;
    }

    vector<pair<int,int>> C(n+1, {INT_MAX, INT_MAX});

    vector<int> D(n+1);
    fori(m) {
        int a, b; cin >> a >> b;
        D[a]++;
        //check;
        int B = b;
        if (B < a) {
            B += n;
        }
        if (B - a <= C[a].first - a) {
            C[a].second = C[a].first;
            C[a].first = b;
        }
        else if (B - a < C[a].second - a) {
            C[a].second = b;
        }

    }
    int need = 0;
    for (int i = 1; i <= n; ++i) {
        need = max(D[i], need);
    }

    //*********************
    int circle = 0;

    for (int i = 1; i <= n; ++i) {
        if (D[i] > 2) {
            int z = D[i] - 2;
            m -= z;
            circle = max(circle, z);
        }
        if (D[i] == need) {
            //nothing
        }
        else if (D[i] + 1 == need) {
            C[i].second = INT_MAX;
        }
        else {
            C[i].second = INT_MAX;
            C[i].first = INT_MAX;
        }
    }
    //***************
    for (int i = 1; i <= n; ++i) {
        if (C[i].first != INT_MAX) {
            A[i][C[i].first]++;
        }
        if (C[i].second != INT_MAX) {
            A[i][C[i].second]++;
        }
    }

    vector<vector<int>> OG = A;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        int pos = start;
        int ans = circle * n;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                int idx = INT_MAX;
                if (C[pos].second != INT_MAX && A[pos][C[pos].second] != 0) {
                    idx = C[pos].second;
                }
                else if (C[pos].first != INT_MAX && A[pos][C[pos].first] != 0) {
                    idx = C[pos].first;
                }
                else {
                    idx = pos;
                }
                //check if there any candies left
                if (A[pos][idx] != INT_MAX && idx != pos) {
                    A[pos][idx]--;
                    Backpack[idx]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>
using namespace std;

ifstream fin("input.txt");
ofstream fout("output.txt");

bool isPrime(long long int x) { if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
    for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }

void primeFactors(long long n, set<long long> &Fac) {
    // Print the number of 2s that divide n
    while (n%2 == 0)
    {
        Fac.insert(2);
        n = n/2;
    }

    // n must be odd at this point.  So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            Fac.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        Fac.insert(n);
}
int NumDigits(int x)
{
    //x = abs(x);
    return (x < 10 ? 1 :
        (x < 100 ? 2 :
        (x < 1000 ? 3 :
        (x < 10000 ? 4 :
        (x < 100000 ? 5 :
        (x < 1000000 ? 6 :
        (x < 10000000 ? 7 :
        (x < 100000000 ? 8 :
        (x < 1000000000 ? 9 :
        10)))))))));
}

inline void boostIO() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    cout.precision(10);
}

typedef long long int ll;
typedef long double ld;
#define fori(n) for(int i = 0; i < (n); ++i)
#define forj(n) for(int j = 0; j < (n); ++j)
#define fork(n) for(int k = 0; k < (n); ++k)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))

#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cerr << #x << " " << x << endl;
#define debug_p(x) cerr << #x << " " << x.ff << " " << x.ss << endl;
#define debug_v(x) cerr << #x << " "; for (auto ii : x) cout << ii << " "; cout << endl;
#define debug_vp(x) cerr << #x << " "; for (auto ii : x) cout << '[' << ii.ff << " " << ii.ss << ']'; cout << endl

//#define endl '\n'
#define Return cerr<<endl<<"RUNTIME: "<<1.0*clock()/CLOCKS_PER_SEC << " s" <<endl; return 0;

ll Pow10[19] = {(ll)0,(ll)1e1,(ll)1e2,(ll)1e3,(ll)1e4,(ll)1e5,(ll)1e6,(ll)1e7,(ll)1e8,(ll)1e9,(ll)1e10,
                (ll)1e11,(ll)1e12,(ll)1e13,(ll)1e14,(ll)1e15,(ll)1e16,(ll)1e17,(ll)1e18};
//be careful with pow(), cuz it returns NOT AN INTEGER

//int mid = low + ((high - low) / 2);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
/*
struct Mine {
    char c = '-';
    int i = 0;
};

struct comp {
    bool operator()(Mine const & a, Mine const & b) {
        return a.i >= b.i;
    }
};
set<Mine, comp> A;
*/
//Cartesian tree (Treap)

//__builtin_clz(int); amount of 0 in the begining
//__builtin_ctz(int); amoint of 0 in the end
//__builtin_popcount(int); amount of 1

//memset(dp, -1, sizeof dp);
#define int long long
template <class T> struct Fenwick {
    vector<T> V;
    Fenwick(int n): V(n) {}
    void add(size_t i, T x) { for (; i < V.size(); i |= i + 1) V[i] += x; }
    T sum(int i) { T r = T(); for (--i; i >= 0; i = (i & (i + 1)) - 1) r += V[i]; return r; }
    T sum(int l, int r) { return sum(r) - sum(l); }
};
struct Edge {
    int x, y, w;

    //Edge(int u, int v, int w) : u(u), v(v), w(w) {}

    // order edges by weight
    bool operator <(const Edge& z) const {
        return w < z.w;
    }
};

int MOD = 1e9 + 7;
#define PI 3.14159265

int32_t main() {
    boostIO();
    int n, m; cin >> n >> m;

    vector<vector<int>> A(n+1, vector<int> (n+1));
    vector<int> Index(n+1);
    for (int i = 1; i <= n; ++i) {
        Index[i] = i-1;
        if (Index[i] < 1) {
            Index[i] += n;
        }
        A[i][i] = INT_MAX;
    }

    vector<pair<int,int>> C(n+1, {INT_MAX, INT_MAX});

    vector<int> D(n+1);
    fori(m) {
        int a, b; cin >> a >> b;
        D[a]++;
        //check;
        int B = b;
        if (B < a) {
            B += n;
        }
        if (B - a <= C[a].first - a) {
            C[a].second = C[a].first;
            C[a].first = b;
        }
        else if (B - a < C[a].second - a) {
            C[a].second = b;
        }

    }

    int circle = 0;

    for (int i = 1; i <= n; ++i) {
        if (D[i] > 2) {
            int z = D[i] - 2;
            m -= z;
            circle = max(circle, z);
        }
    }

    for (int i = 1; i <= n; ++i) {
        if (C[i].first != INT_MAX) {
            A[i][C[i].first]++;
        }
        if (C[i].second != INT_MAX) {
            A[i][C[i].second]++;
        }
    }

    /*
    fori(m) {
        int a, b; cin >> a >> b;
        A[a][b]++;
    }
    */

    vector<vector<int>> OG = A;
    vector<int> OG2 = Index;

    for (int start = 1; start <= n; ++start) {
        A = OG;
        Index = OG2;
        int pos = start;
        int ans = circle * n;
        int candies = m;
        vector<int> Backpack(n+1);

        while(candies >= 0) {
            //taking a candy;
                //finding candy to take
                while(A[pos][Index[pos]] == 0) {
                    Index[pos]--;
                    if (Index[pos] < 1) {
                        Index[pos] += n;
                    }
                }
                //check if there any candies left
                if (A[pos][Index[pos]] != INT_MAX) {
                    A[pos][Index[pos]]--;
                    Backpack[Index[pos]]++;
                }

            //giving candies
                candies -= Backpack[pos];
                Backpack[pos] = 0;

            if (candies == 0) {
                break;
            }
            ans++;
            pos++;
            if (pos > n)
                pos = 1;
        }
        cout << ans << " ";
    }

    Return;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
//#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N], cpy[N];
int n, m;

int main()
{
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
	}

	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
		}
	}

	erep(i, 1, n)
	{
		erep(j, 1, n)
			cpy[j] = node[j];
		int curr = temp;
		int steps = 0;
		multiset<int> ms;
		if (!cpy[i].empty())
		{
			ms.insert(cpy[i].back());
			cpy[i].pop_back(), curr--;
		}

		int idx = i;
		while (curr > 0 || !ms.empty())
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			ms.erase(idx);
			if (!cpy[idx].empty())
				ms.insert(cpy[idx].back()), cpy[idx].pop_back(), curr--;
		}
//		return 0;
		cout << steps << " ";
//		return 0;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N];
int sz[N];
int n, m;

int ms[N], have;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
	}

	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
		}
	}

	erep(i, 1, n)
	{
		erep(j, 1, n)
			sz[j] = sz(node[j]) - 1;
		int curr = temp;
		int steps = 0;

		if (sz[i] >= 0)
		{
			ms[node[i][sz[i]]]++;
			have++;
			sz[i]--, curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (sz[idx] >= 0)
				ms[node[idx][sz[idx]]]++, have++, sz[idx]--, curr--;
		}
//		return 0;
		cout << steps << " ";
//		return 0;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N];
int sz[N];
int n, m;

int ms[N], have, memo[N], rev[N], first[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
		rev[v]++;
	}
	reset(first, -1);
	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
			first[i] = node[i].back();
		}
	}
	reset(memo, -1);

//	erep(i, 1, n)
//		cout << i << " " << first[i] << endl;

	for (int i = n; i >= 1; i--)
	{
		if (!rev[i])
			continue;
		erep(j, 1, n)
			sz[j] = sz(node[j]) - 1;
		int curr = temp;
		int steps = 0;

		if (sz[i] >= 0)
		{
			ms[node[i][sz[i]]]++;
			have++;
			sz[i]--, curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;

			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (sz[idx] >= 0)
				ms[node[idx][sz[idx]]]++, have++, sz[idx]--, curr--;
		}
		memo[i] = steps;
	}

	for (int i = n; i >= 1; i--)
	{
		if (rev[i])
			continue;
		int nxt = i == n ? 1 : i + 1;
		if (first[first[i]] != -1)
		{
			memo[i] = 1 + memo[nxt];
			continue;
		}
		erep(j, 1, n)
			sz[j] = sz(node[j]) - 1;
		int curr = temp;
		int steps = 0;

		if (sz[i] >= 0)
		{
			ms[node[i][sz[i]]]++;
			have++;
			sz[i]--, curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (sz[idx] >= 0)
				ms[node[idx][sz[idx]]]++, have++, sz[idx]--, curr--;
		}
		memo[i] = steps;
	}

	erep(i, 1, n)
		cout << memo[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N], cpy[N];
int n, m;

int ms[N], have;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
	}

	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
		}
	}

	erep(i, 1, n)
	{
		erep(j, 1, n)
			cpy[j] = node[j];
		int curr = temp;
		int steps = 0;

		if (!cpy[i].empty())
		{
			ms[cpy[i].back()]++;
			have++;
			cpy[i].pop_back(), curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (!cpy[idx].empty())
				ms[cpy[idx].back()]++, have++, cpy[idx].pop_back(), curr--;
		}
//		return 0;
		cout << steps << " ";
//		return 0;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
//#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N], cpy[N];
int n, m;

int main()
{
//	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
	}

	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
		}
	}

	erep(i, 1, n)
	{
		erep(j, 1, n)
			cpy[j] = node[j];
		int curr = temp;
		int steps = 0;
		multiset<int> ms;
		if (!cpy[i].empty())
		{
			ms.insert(cpy[i].back());
			cpy[i].pop_back(), curr--;
		}

		int idx = i;
		while (curr > 0 || !ms.empty())
		{
//			cout << curr << " " << idx << " " << steps << endl;
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			ms.erase(idx);
			if (!cpy[idx].empty())
				ms.insert(cpy[idx].back()), cpy[idx].pop_back(), curr--;
		}
//		return 0;
		cout << steps << " ";
//		return 0;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 5e3 + 5;
deque<int> node[N];
int sz[N];
int n, m;

int ms[N], have, memo[N], rev[N], first[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;

	int temp = m;
	while (m--)
	{
		int u, v;
		cin >> u >> v;
		node[u].push_back(v);
		rev[v]++;
	}
	reset(first, -1);
	erep(i, 1, n)
	{
		sort(all(node[i]));
		int idx = lower_bound(all(node[i]), i) - node[i].begin();

		if (idx != sz(node[i]))
		{
			while (idx--)
			{
				node[i].push_back(node[i].front());
				node[i].pop_front();
			}
			first[i] = node[i][0];
		}
	}
	reset(memo, -1);

	for (int i = n; i >= 1; i--)
	{
		if (!rev[i])
			continue;
		erep(j, 1, n)
			sz[j] = sz(node[j]) - 1;
		int curr = temp;
		int steps = 0;

		if (sz[i] >= 0)
		{
			ms[node[i][sz[i]]]++;
			have++;
			sz[i]--, curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;

			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (sz[idx] >= 0)
				ms[node[idx][sz[idx]]]++, have++, sz[idx]--, curr--;
		}
		memo[i] = steps;
	}

	for (int i = n; i >= 1; i--)
	{
		if (rev[i])
			continue;
		int nxt = i == n ? 1 : i + 1;
		if (first[i] != nxt)
		{
			memo[i] = 1 + memo[nxt];
			continue;
		}
		erep(j, 1, n)
			sz[j] = sz(node[j]) - 1;
		int curr = temp;
		int steps = 0;

		if (sz[i] >= 0)
		{
			ms[node[i][sz[i]]]++;
			have++;
			sz[i]--, curr--;
		}

		int idx = i;
		while (curr > 0 || have)
		{
			idx++;
			if (idx > n)
				idx = 1;
			steps++;
			if (ms[idx])
			{
				have -= ms[idx];
				ms[idx] = 0;
			}
			if (sz[idx] >= 0)
				ms[node[idx][sz[idx]]]++, have++, sz[idx]--, curr--;
		}
		memo[i] = steps;
	}

	erep(i, 1, n)
		cout << memo[i] << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 5e3 + 5;
vector<pii> node[N];
int n, m;

int fix(int x, int y)
{
	int dist = y - x;
	while (dist < 0)
		dist += n;
	return dist;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;

	while (m--)
	{
		int u, v;
		cin >> u >> v;
		int dist = fix(u, v);
		node[u].push_back(
		{ dist, v });
	}

	erep(i, 1, n)
		sort(all(node[i]));

	erep(i, 1, n)
	{
		int res = 0;

		erep(j, 1, n)
		{
			if (node[j].empty())
				continue;
			int dist = fix(i, j);
			res = max(res, node[j][0].first + dist + (sz(node[j]) - 1) * n);
		}

		cout << res << " ";
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pr(x) cout << #x << " = " << x << '\n';

using ll = long long;
using ld = long double;

const ll inf = 1e9;

int get_dist(int st, int sw, int n) {
	return (sw - st + n) % n;
}

int get_ans(int i, int n, int m, vector <int>& sweet, vector<int>& min_dist_sw) {
	int k = 0;
	int ans = 0;
	while (k < n) {
		int st = i + k;
		if (st > n) st %= n;
		ans = max(ans, k + (sweet[st] - 1)*n + min_dist_sw[st]);
		k++;
	}

	return ans;
}

void solve() {
	int n, m;
	cin >> n >> m;

	vector <int> sweet(n + 1);
	vector <int> min_dist_sw(m + 1);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		sweet[a]++;
		int len = get_dist(a, b, n);

		if (min_dist_sw[a] > len || min_dist_sw[a] == 0)
			min_dist_sw[a] = len;
	}

	// pr(min_dist_sw[0]);
	// pr(min_dist_sw[1]);

	for (int i = 0; i < n; i++) {
		// int ans = get_ans(i,n,m,sweet, min_dist_sw);
		// cout << "ANS: " << ans << endl;
		cout << get_ans(i, n, m, sweet, min_dist_sw) << ' ';
	}

	cout << endl;

}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	while (t--){
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pr(x) cout << #x << " = " << x << '\n';

using ll = long long;
using ld = long double;

const ll inf = 1e9;

int get_dist(int from, int to, int n) {
	return (to - from + n) % n;
}

int get_ans(int i, int n, int m, vector <int>& sweet, vector<int>& min_dist_sw) {
	int ans = 0;
	for (int j = 1; j <= n; j++) {
		if (sweet[j] == 0) continue;
		int cur_ans = (sweet[j] - 1) * n + get_dist(i, j, n) + min_dist_sw[j];
		ans = max(ans, cur_ans);
	}

	return ans;
}

void solve() {
	int n, m;
	cin >> n >> m;

	vector <int> sweet(5002);
	vector <int> min_dist_sw(20002);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		sweet[a]++;
		int len = get_dist(a, b, n);

		if (min_dist_sw[a] > len || min_dist_sw[a] == 0)
			min_dist_sw[a] = len;
	}

	// for (int i = 1; i <= n; i++)

	for (int i = 1; i <= n; i++)
		cout << get_ans(i, n, m, sweet, min_dist_sw) << ' ';

	cout << endl;

}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	while (t--){
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pr(x) cout << #x << " = " << x << '\n';

using ll = long long;
using ld = long double;

const ll inf = 1e9;

int get_dist(int st, int sw, int n) {
	return (sw - st + n) % n;
}

int get_ans(int i, int n, int m, vector <int>& sweet, vector<int>& min_dist_sw) {
	int k = 0;
	int ans = 0;
	while (k < n) {
		int st = i + k;
		if (st > n) st %= n;
		ans = max(ans, k + (sweet[st] - 1)*n + min_dist_sw[st]);
		k++;
	}

	return ans;
}

void solve() {
	int n, m;
	cin >> n >> m;

	vector <int> sweet(n + 1);
	vector <int> min_dist_sw(m + 1);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		sweet[a]++;
		int len = get_dist(a, b, n);

		if (min_dist_sw[a] > len || min_dist_sw[a] == 0)
			min_dist_sw[a] = len;
	}

	// pr(min_dist_sw[0]);
	// pr(min_dist_sw[1]);

	for (int i = 1; i <= n; i++) {
		// int ans = get_ans(i,n,m,sweet, min_dist_sw);
		// cout << "ANS: " << ans << endl;
		cout << get_ans(i, n, m, sweet, min_dist_sw) << ' ';
	}

	cout << endl;

}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	while (t--){
		solve();
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pr(x) cout << #x << " = " << x << '\n';

using ll = long long;
using ld = long double;

const ll inf = 1e9;

int get_dist(int st, int sw, int n) {
	return (sw - st + n) % n;
}

int get_ans(int i, int n, int m, vector <int>& sweet, vector<int>& min_dist_sw) {
	int k = 0;
	int ans = 0;
	while (k < n) {
		int st = i + k;
		if (st > n) st %= n;
		ans = max(ans, k + (sweet[st] - 1)*n + min_dist_sw[st]);
		k++;
	}

	return ans;
}

void solve() {
	int n, m;
	cin >> n >> m;

	vector <int> sweet(5002);
	vector <int> min_dist_sw(20002);

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		sweet[a]++;
		int len = get_dist(a, b, n);

		if (min_dist_sw[a] > len || min_dist_sw[a] == 0)
			min_dist_sw[a] = len;
	}

	// pr(min_dist_sw[0]);
	// pr(min_dist_sw[1]);

	for (int i = 1; i <= n; i++) {
		// int ans = get_ans(i,n,m,sweet, min_dist_sw);
		// cout << "ANS: " << ans << endl;
		cout << get_ans(i, n, m, sweet, min_dist_sw) << ' ';
	}

	cout << endl;

}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	while (t--){
		solve();
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<string>
#include<random>
#include<cstdio>

using namespace std;

long long cur, n;

inline bool cmp(int a, int b) {
	int d1 = a - cur, d2 = b - cur;
	if (d1 < 0) {
		d1 += n;
	}
	if (d2 < 0) {
		d2 += n;
	}
	return d1 < d2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	//cin >> _;
	while (_--) {
		int k;
		cin >> n >> k;
		vector<vector<int>> b(n + 1);
		for (int i = 0; i < k; i++) {
			int x, y;
			cin >> x >> y;
			b[x].push_back(y);
		}
		for (int i = 1; i <= n; i++) {
			cur = i;
			sort(b[i].begin(), b[i].end(), cmp);
			/*cout << i << ": ";
			for (int j : b[i]) {
				cout << j << " ";
			}
			cout << endl;*/
		}
		for (int i = 1; i <= n; i++) {
			//cout << "------ " << i << endl;
			long long ans = 0;
			for (int j = 0; j <= n - 1; j++) {
				int it = i + j;
				if (i + j > n) {
					it -= n;
				}
				int d = 0;
				//cout << "--- " << it << endl;
				if (b[it].size()) {
					d = b[it][0] - it;
					if (d < 0) {
						d += n;
					}
				}
				int dist = it - i;
				if (dist < 0) {
					dist += n;
				}
				/*cout << d << " " << dist << " " << b[it].size() << endl;
				cout << n * max(0, (int)b[it].size() - 1) + d + dist << endl;*/
				ans = max(ans, n * max(0ll, (long long)b[it].size() - 1) + d + dist);
			}
			cout << ans << " ";
		}
		cout << endl;
	}
}