#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;
struct pair_hash {
  template <class T1, class T2>
  std::size_t operator()(const std::pair<T1, T2> &p) const {
    auto h1 = std::hash<T1>{}(p.first);
    auto h2 = std::hash<T2>{}(p.second);
    return h1 ^ h2;
  }
};
long long pw(long long te, long long tee) {
  if (tee == 0) return 1;
  long long res = pw(te, tee / 2);
  return (tee % 2 ? te * res * res : res * res);
}
long long n, m, b[MAXN], tr, a[MAXN], aa[MAXN];
set<long long> st[MAXN], stt[MAXN];
set<pair<long long, long long>> t;
void Read_input() {
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) cin >> a[i] >> b[i], st[a[i]].insert(i);
}
bool check() {
  for (long long i = 1; i <= m; i++)
    if (aa[i] != b[i]) return true;
  return false;
}
void Solve() {
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) aa[j] = a[j];
    for (long long j = 1; j <= n; j++) stt[j] = st[j];
    tr = i;
    long long time = -1;
    while (check()) {
      time++;
      while (true) {
        auto itr = t.lower_bound({tr, 0});
        if (itr != t.end() and itr->first == tr) {
          aa[itr->second] = tr;
          t.erase(itr);
        } else
          break;
      }
      if (!stt[tr].empty()) {
        long long o = 0, u = 0;
        for (auto oo : stt[tr]) {
          if (b[oo] < tr) {
            if (b[oo] + n - tr > u) {
              u = b[oo] + n - tr, o = oo;
            }
          } else {
            if (b[oo] - tr > u) {
              u = b[oo] - tr, o = oo;
            }
          }
        }
        aa[o] = -1;
        t.insert({b[o], o});
        stt[tr].erase(o);
      }
      tr++;
      if (tr > n) tr -= n;
    }
    cout << time << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Read_input(), Solve();
  return 0;
}
