#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  T ans = 0;
  short f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = (ans << 1) + (ans << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = ans * f;
}
int L[500], R[500], pos[200010];
int a[500], b[500];
int t;
int n, m, l, r;
int s[200010];
long long ans = 0;
vector<int> v[500];
int ask(int l, int r, int k) {
  if (l > r) return 0;
  int p = pos[l], q = pos[r];
  long long ans = 0;
  if (p == q) {
    for (int i = l; i <= r; i++) ans += s[i] < k;
    return ans;
  }
  for (int i = p + 1; i <= q - 1; i++)
    ans += lower_bound(v[i].begin(), v[i].end(), k) - v[i].begin();
  for (int i = l; i <= R[p]; i++) ans += s[i] < k;
  for (int i = L[q]; i <= r; i++) ans += s[i] < k;
  return ans;
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++) s[i] = i;
  t = sqrt(n);
  for (int i = 1; i <= t; i++) {
    L[i] = (i - 1) * sqrt(n) + 1;
    R[i] = i * sqrt(n);
  }
  if (R[t] < n) R[++t] = n, L[t] = R[t - 1] + 1;
  for (int i = 1; i <= t; i++)
    for (int j = L[i]; j <= R[i]; j++) pos[j] = i, v[i].push_back(j);
  while (m--) {
    read(l), read(r);
    if (l == r) {
      printf("%lld\n", ans);
      continue;
    }
    if (l > r) swap(l, r);
    int p = pos[l], q = pos[r];
    ans += (ask(l + 1, r - 1, s[r]) - ask(l + 1, r - 1, s[l])) << 1;
    ans += (s[l] < s[r]) * 2 - 1;
    if (p != q) {
      v[p].erase(lower_bound(v[p].begin(), v[p].end(), s[l]));
      v[p].insert(lower_bound(v[p].begin(), v[p].end(), s[r]), s[r]);
      v[q].erase(lower_bound(v[q].begin(), v[q].end(), s[r]));
      v[q].insert(lower_bound(v[q].begin(), v[q].end(), s[l]), s[l]);
    }
    swap(s[l], s[r]);
    printf("%lld\n", ans);
  }
}
