#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n, m, bel[N], L[N], R[N], a[N];
vector<int> s[N];
long long ans;
int query(int l, int r, int v) {
  if (l > r) return 0;
  int res = 0;
  if (bel[l] == bel[r]) {
    for (register int i = l; i <= r; i++)
      if (a[i] < v) res++;
    return res;
  }
  for (register int i = l; i <= R[bel[l]]; i++)
    if (a[i] < v) res++;
  for (register int i = bel[l] + 1; i <= bel[r] - 1; i++)
    res += lower_bound(s[i].begin(), s[i].end(), v) - s[i].begin();
  for (register int i = L[bel[r]]; i <= r; i++)
    if (a[i] < v) res++;
  return res;
}
int change(int x, int y) {
  s[bel[x]].erase(lower_bound(s[bel[x]].begin(), s[bel[x]].end(), a[x]));
  s[bel[y]].erase(lower_bound(s[bel[y]].begin(), s[bel[y]].end(), a[y]));
  swap(a[x], a[y]);
  s[bel[x]].insert(upper_bound(s[bel[x]].begin(), s[bel[x]].end(), a[x]), a[x]);
  s[bel[y]].insert(upper_bound(s[bel[y]].begin(), s[bel[y]].end(), a[y]), a[y]);
}
int main() {
  n = read(), m = read();
  int len = sqrt(n);
  for (register int i = 1; i <= n; i++) {
    bel[i] = (i - 1) / len + 1, s[bel[i]].push_back(a[i] = i);
    if (!L[bel[i]]) L[bel[i]] = i;
    R[bel[i]] = i;
  }
  while (m--) {
    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);
  }
}
