#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int BN = 450;
vector<int> b[BN];
int a[MAXN];
long long ans;
int Query(int l, int r, int v) {
  if (l > r) return 0;
  int ret = 0;
  while (l % BN != 0 && l <= r)
    if (a[l++] < v) ret++;
  while (r % BN != 0 && l <= r)
    if (a[r--] < v) ret++;
  if (r % BN == 0 && l <= r && a[r] < v) ret++;
  l /= BN;
  r /= BN;
  while (l < r) {
    ret += lower_bound(b[l].begin(), b[l].end(), v) - b[l].begin();
    l++;
  }
  return ret;
}
void Replace(int pos, int v) {
  int bi = pos / BN;
  b[bi].erase(lower_bound(b[bi].begin(), b[bi].end(), a[pos]));
  b[bi].insert(upper_bound(b[bi].begin(), b[bi].end(), v), v);
  a[pos] = v;
  return;
}
int main() {
  int n, qn;
  scanf("%d%d", &n, &qn);
  for (int i = 0; i < n; ++i) b[i / BN].push_back(i + 1), a[i] = i + 1;
  while (qn--) {
    int l, r, tl, tr, tem;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    if (r < l) swap(l, r);
    if (l < r) {
      tl = Query(l + 1, r, a[l]);
      tr = Query(l, r - 1, a[r]);
      ans = ans - tl + (r - l - tl);
      ans = ans + tr - (r - l - tr);
      if (a[l] < a[r])
        ans--;
      else
        ans++;
      tem = a[l];
      Replace(l, a[r]);
      Replace(r, tem);
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
