#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int K = 500;
const int MAXN = 1 << 18;
int sorted[MAXN], a[MAXN];
int rk(int ql, int qr, int v) {
  int l = ql / K, r = qr / K;
  if (l == r) return count_if(a + ql, a + qr, [=](int a) { return a <= v; });
  int ret = 0;
  for (int i = ql; i < (l + 1) * K; ++i) ret += a[i] <= v;
  for (int i = l + 1; i < r; ++i) {
    ret +=
        upper_bound(sorted + i * K, sorted + i * K + K, v) - (sorted + i * K);
  }
  for (int i = r * K; i < qr; ++i) ret += a[i] <= v;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; ++i) sorted[i] = a[i] = i;
  long long cur = 0;
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    if (r < l) swap(l, r);
    if (l < r) {
      cur += (a[l] < a[r]) - (a[r] < a[l]);
      cur += r - l - 1 - 2 * rk(l + 1, r, a[l]);
      cur += 2 * rk(l + 1, r, a[r]) - (r - l - 1);
      swap(a[l], a[r]);
      for (int j : {l, r}) {
        int rb = min(j / K * K + K, n);
        copy(a + j / K * K, a + rb, sorted + j / K * K);
        sort(sorted + j / K * K, sorted + rb);
      }
    }
    cout << cur << '\n';
  }
}
