#include <bits/stdc++.h>
using namespace std;
const long long N = 2000000;
const long long inf = 0x7fffffff;
long long a, b, s[N + 10], k, bel[N + 10];
vector<long long> st[N + 10];
inline long long query(long long l, long long r, long long p) {
  if (l > r) return 0;
  long long sum = 0;
  for (long long i = l; i <= min(k * bel[l], r); i++)
    if (s[i] < p) sum++;
  if (bel[l] == bel[r]) return sum;
  for (long long i = k * (bel[r] - 1) + 1; i <= r; i++)
    if (s[i] < p) sum++;
  for (long long i = bel[l] + 1; i <= bel[r] - 1; i++)
    sum += lower_bound(st[i].begin(), st[i].end(), p) - st[i].begin();
  return sum;
}
inline void change(long long l, long long r) {
  if (bel[l] != bel[r]) {
    st[bel[l]].erase(lower_bound(st[bel[l]].begin(), st[bel[l]].end(), s[l]));
    st[bel[l]].insert(upper_bound(st[bel[l]].begin(), st[bel[l]].end(), s[r]),
                      s[r]);
    st[bel[r]].erase(lower_bound(st[bel[r]].begin(), st[bel[r]].end(), s[r]));
    st[bel[r]].insert(upper_bound(st[bel[r]].begin(), st[bel[r]].end(), s[l]),
                      s[l]);
  }
  swap(s[l], s[r]);
}
signed main() {
  scanf("%lld%lld", &a, &b);
  k = ceil(sqrt(b));
  long long ans = 0, x, y;
  for (long long i = 1; i <= a; i++) {
    s[i] = i;
    bel[i] = (i - 1) / k + 1;
    st[(i - 1) / k + 1].push_back(i);
  }
  for (long long i = 1; i <= b; i++) {
    scanf("%lld%lld", &x, &y);
    if (x > y) swap(x, y);
    if (x == y) {
      printf("%lld\n", ans);
      continue;
    }
    long long tmp =
        -2 * query(x + 1, y - 1, s[x]) + 2 * query(x + 1, y - 1, s[y]);
    ans = ans + tmp;
    ans += s[x] < s[y] ? 1 : -1;
    change(x, y);
    printf("%lld\n", ans);
  }
  return 0;
}
