#include <bits/stdc++.h>
using namespace std;
const int bl = 500;
const int maxi = 400000;
int n, q;
int a[maxi], b[maxi], l, r;
long long manji(long long val, int l, int r) {
  if (l > r) return 0;
  long long ans = 0;
  if (l / bl == r / bl) {
    for (int i = l; i <= r; i++)
      if (a[i] < val) ans++;
    return ans;
  }
  int prvi = (l / bl);
  int zadnji = (r / bl);
  for (int i = l; i < (prvi + 1) * bl; i++)
    if (a[i] < val) ans++;
  for (int i = zadnji * bl; i <= r; i++)
    if (a[i] < val) ans++;
  for (int i = prvi + 1; i <= zadnji - 1; i++) {
    int lef = i * bl - 1;
    int rig = (i + 1) * bl;
    while (lef < rig - 1) {
      int tr = (lef + rig) / 2;
      if (b[tr] < val)
        lef = tr;
      else
        rig = tr;
    }
    ans += lef;
  }
  return ans;
}
void zameni(int l, int r) {
  swap(a[l], a[r]);
  int prvi = (l / bl);
  int zadnji = (r / bl);
  for (int i = prvi * bl; i < (prvi + 1) * bl; i++) b[i] = a[i];
  for (int i = zadnji * bl; i < (zadnji + 1) * bl; i++) b[i] = a[i];
  sort(b + prvi * bl, b + (prvi + 1) * bl);
  sort(b + zadnji * bl, b + (zadnji + 1) * bl);
}
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    a[i] = i;
    b[i] = i;
  }
  long long cur = 0;
  while (q--) {
    scanf("%d%d", &l, &r);
    int p = max(l, r);
    l = min(l, r);
    r = p;
    if (l == r)
      printf("%lld\n", cur);
    else {
      if (a[l] > a[r])
        cur--;
      else
        cur++;
      long long tot = manji(a[l], l + 1, r - 1);
      cur -= tot;
      cur += (r - l - 1 - tot);
      tot = manji(a[r], l + 1, r - 1);
      cur += tot;
      cur -= (r - l - 1 - tot);
      printf("%lld\n", cur);
    }
    zameni(l, r);
  }
  return 0;
}
