#include <bits/stdc++.h>
using namespace std;
int len, n, k;
int pos[200005], a[200005], L[500], R[500];
long long ans = 0;
vector<int> g[200005];
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
inline void change(int x, int y) {
  if (pos[x] != pos[y]) {
    g[pos[x]].erase(lower_bound(g[pos[x]].begin(), g[pos[x]].end(), a[x])),
        g[pos[x]].insert(upper_bound(g[pos[x]].begin(), g[pos[x]].end(), a[y]),
                         a[y]);
    g[pos[y]].erase(lower_bound(g[pos[y]].begin(), g[pos[y]].end(), a[y])),
        g[pos[y]].insert(upper_bound(g[pos[y]].begin(), g[pos[y]].end(), a[x]),
                         a[x]);
  }
  swap(a[x], a[y]);
}
int query(int l, int r, int v) {
  if (l > r) return 0;
  int cnt = 0;
  for (int i = l; i <= min(R[pos[l]], r); ++i) cnt += (a[i] < v);
  if (pos[l] == pos[r]) return cnt;
  for (int i = L[pos[r]]; i <= r; ++i) cnt += (a[i] < v);
  for (int i = pos[l] + 1; i <= pos[r] - 1; ++i)
    cnt += lower_bound(g[i].begin(), g[i].end(), v) - g[i].begin();
  return cnt;
}
int main() {
  n = read(), k = read(), len = sqrt(n);
  for (int i = 1; i <= n; i++) a[i] = i;
  for (int i = 1; i <= n; i++)
    pos[i] = (i - 1) / len + 1, g[pos[i]].push_back(i);
  for (int i = 1; i <= pos[n]; i++) L[i] = (i - 1) * len + 1, R[i] = i * len;
  for (int t = 1; t <= k; t++) {
    int l = read(), r = read();
    if (l > r) swap(l, r);
    if (l == r) {
      printf("%lld\n", ans);
      continue;
    }
    ans += 2 * (query(l + 1, r - 1, a[r]) - query(l + 1, r - 1, a[l]));
    if (a[l] < a[r])
      ans++;
    else
      ans--;
    change(l, r);
    printf("%lld\n", ans);
  }
  return 0;
}
