#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[m], b[m];
  vector<priority_queue<int> > c(n);
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    if (a[i] > b[i]) {
      b[i] = b[i] + n;
    }
    c[a[i]].push(b[i]);
  }
  int ans[n];
  priority_queue<int> pq[n];
  for (int i = 0; i < n; i++) pq[i] = c[i];
  for (int x = 0; x < n; x++) {
    for (int i = 0; i < n; i++) c[i] = pq[i];
    unordered_set<int> train;
    int del = 0;
    for (int ii = 0;; ii++) {
      int i = (ii + x) % n;
      if (c[i].size() > 0) {
        del++;
        int k = c[i].top();
        k = k % n;
        c[i].pop();
        train.insert(k);
      }
      if (train.find(i % n) != train.end()) train.erase(i % n);
      if (train.size() == 0 && del == m) {
        ans[x] = ii;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
