#include <bits/stdc++.h>
using namespace std;
int n, m;
int block;
vector<int> b[200005];
int l[200005];
int r[200005];
int a[200005];
int x, y;
long long ans;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    a[i] = i + 1;
  }
  block = (int)sqrt(1.0 * n);
  for (int i = 0; i < n / block; i++) {
    l[i] = i * block;
    r[i] = l[i] + block - 1;
    for (int j = l[i]; j <= r[i]; j++) {
      b[i].push_back(j + 1);
    }
  }
  if (n % block) {
    l[n / block] = (n / block) * block;
    r[n / block] = n - 1;
    for (int j = l[n / block]; j <= r[n / block]; j++) {
      b[n / block].push_back(j + 1);
    }
  }
  while (m--) {
    scanf("%d%d", &x, &y);
    x--;
    y--;
    if (x > y) {
      swap(x, y);
    }
    if (x == y) {
      printf("%I64d\n", ans);
      continue;
    }
    int xx, yy;
    xx = x / block;
    yy = y / block;
    for (int i = xx + 1; i <= yy - 1; i++) {
      int low, high;
      low = lower_bound(b[i].begin(), b[i].end(), a[x]) - b[i].begin();
      high = b[i].size() - low;
      ans -= low;
      ans += high;
    }
    for (int i = xx + 1; i <= yy - 1; i++) {
      int low, high;
      low = lower_bound(b[i].begin(), b[i].end(), a[y]) - b[i].begin();
      high = b[i].size() - low;
      ans += low;
      ans -= high;
    }
    for (int i = x + 1; i <= r[xx] && i < y; i++) {
      if (a[i] > a[x]) {
        ans++;
      } else {
        ans--;
      }
      if (a[i] > a[y]) {
        ans--;
      } else {
        ans++;
      }
    }
    if (xx != yy) {
      for (int i = y - 1; i >= l[yy] && i > x; i--) {
        if (a[i] > a[x]) {
          ans++;
        } else {
          ans--;
        }
        if (a[i] > a[y]) {
          ans--;
        } else {
          ans++;
        }
      }
    }
    if (a[x] < a[y]) {
      ans++;
    } else {
      ans--;
    }
    b[xx].erase(lower_bound(b[xx].begin(), b[xx].end(), a[x]));
    b[yy].erase(lower_bound(b[yy].begin(), b[yy].end(), a[y]));
    b[xx].insert(lower_bound(b[xx].begin(), b[xx].end(), a[y]), a[y]);
    b[yy].insert(lower_bound(b[yy].begin(), b[yy].end(), a[x]), a[x]);
    swap(a[x], a[y]);
    printf("%I64d\n", ans);
  }
  return 0;
}
