#include <bits/stdc++.h>
const long long N = 2e5 + 10;
long long n, T, block, cnt, ans;
long long a[N], pre[N], pos[N], l[N], r[N];
long long ask(long long x, long long k) {
  long long L = l[x], R = r[x], mid, sum = l[x] - 1;
  while (L <= R) {
    mid = L + ((R - L) >> 1);
    if (pre[mid] < k) {
      L = mid + 1;
      sum = mid;
    } else {
      R = mid - 1;
    }
  }
  return sum - (l[x] - 1);
}
long long query(long long L, long long R, long long x, long long sum = 0) {
  if (L > R) {
    return 0;
  }
  if (pos[L] == pos[R]) {
    for (long long i = L; i <= R; i++) {
      if (a[i] < x) {
        sum++;
      }
    }
    return sum;
  }
  for (long long i = L; i <= r[pos[L]]; i++) {
    if (a[i] < x) {
      sum++;
    }
  }
  for (long long i = l[pos[R]]; i <= R; i++) {
    if (a[i] < x) {
      sum++;
    }
  }
  for (long long i = pos[L] + 1; i <= pos[R] - 1; i++) {
    sum += ask(i, x);
  }
  return sum;
}
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin >> n >> T;
  block = std::sqrt(n);
  cnt = n / block + (n % block != 0);
  for (long long i = 1; i <= n; i++) {
    a[i] = pre[i] = i;
    pos[i] = (i - 1) / block + 1;
  }
  for (long long i = 1; i <= cnt; i++) {
    l[i] = (i - 1) * block + 1;
    r[i] = i * block;
  }
  r[cnt] = n;
  for (; T; --T) {
    long long x, y;
    std::cin >> x >> y;
    if (x > y) {
      std::swap(x, y);
    }
    ans += 2 * (query(x + 1, y - 1, a[y]) - query(x + 1, y - 1, a[x]));
    if (a[x] < a[y]) {
      ans++;
    }
    if (a[x] > a[y]) {
      ans--;
    }
    std::swap(a[x], a[y]);
    for (long long i = l[pos[x]]; i <= r[pos[x]]; i++) {
      pre[i] = a[i];
    }
    for (long long i = l[pos[y]]; i <= r[pos[y]]; i++) {
      pre[i] = a[i];
    }
    std::sort(pre + l[pos[x]], pre + r[pos[x]] + 1);
    std::sort(pre + l[pos[y]], pre + r[pos[y]] + 1);
    std::cout << ans << "\n";
  }
  return 0;
}
