#include <bits/stdc++.h>
using namespace std;
int n, B, m;
int a[200010], pos[200010];
vector<int> v[450];
int Swap(int x, int y) {
  int px = pos[x], py = pos[y];
  v[py].erase(lower_bound(v[py].begin(), v[py].end(), a[y]));
  v[py].insert(lower_bound(v[py].begin(), v[py].end(), a[x]), a[x]);
  v[px].erase(lower_bound(v[px].begin(), v[px].end(), a[x]));
  v[px].insert(lower_bound(v[px].begin(), v[px].end(), a[y]), a[y]);
  swap(a[x], a[y]);
}
int query(int l, int r, int up, int low) {
  if (l > r) return 0;
  int res = 0;
  if (pos[l] == pos[r]) {
    for (int i = l; i <= r; i++)
      if (a[i] >= up && a[i] <= low) res++;
    return res;
  } else {
    for (int i = l; i <= (pos[l] + 1) * B - 1; i++)
      if (a[i] >= up && a[i] <= low) res++;
    for (int i = pos[r] * B; i <= r; i++)
      if (a[i] >= up && a[i] <= low) res++;
    for (int i = pos[l] + 1; i < pos[r]; i++) {
      int it = lower_bound(v[i].begin(), v[i].end(), up) - v[i].begin(),
          it1 = upper_bound(v[i].begin(), v[i].end(), low) - v[i].begin();
      res += (it1 - it);
    }
    return res;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  B = sqrt(n);
  for (int i = 1; i <= n; i++) a[i] = i, v[i / B].push_back(i), pos[i] = i / B;
  long long res = 0;
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    if (x == y) {
      printf("%lld\n", res);
      continue;
    }
    if (a[x] > a[y]) {
      int cnt = query(x + 1, y - 1, a[y] + 1, a[x] - 1);
      res -= (2ll * cnt + 1);
      printf("%lld\n", res);
    } else {
      int cnt = query(x + 1, y - 1, a[x] + 1, a[y] - 1);
      res += (2ll * cnt + 1);
      printf("%lld\n", res);
    }
    Swap(x, y);
  }
  return 0;
}
