#include <bits/stdc++.h>
using namespace std;
vector<int> s[550];
vector<int>::iterator iter, iter1;
int a[200005], d;
int main() {
  int t, k, i, j, c, n, m;
  cin >> n >> m;
  d = sqrt(n);
  for (i = 0; i < n; i++) {
    a[i] = i;
    s[i / d].push_back(i);
  }
  long long int ans = 0;
  while (m--) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (x > y) swap(x, y);
    if (x == y) {
      cout << ans << endl;
      continue;
    }
    for (i = x + 1; i < y;) {
      if (i % d == 0 && y - 1 >= i + d - 1) {
        iter = upper_bound(s[i / d].begin(), s[i / d].end(), a[x]);
        long long int temp = distance(iter, s[i / d].end());
        ans = ans + 2 * temp - d;
        i += d;
      } else {
        if (a[i] > a[x])
          ans++;
        else if (a[i] < a[x])
          ans--;
        i++;
      }
    }
    for (i = x + 1; i < y;) {
      if (i % d == 0 && y - 1 >= i + d - 1) {
        iter = upper_bound(s[i / d].begin(), s[i / d].end(), a[y]);
        long long int temp = distance(iter, s[i / d].end());
        ans = ans + d - 2 * temp;
        i += d;
      } else {
        if (a[i] > a[y])
          ans--;
        else if (a[i] < a[y])
          ans++;
        i++;
      }
    }
    if (a[x] < a[y])
      ans++;
    else if (a[y] < a[x])
      ans--;
    i = x / d;
    j = y / d;
    iter = lower_bound(s[i].begin(), s[i].end(), a[x]);
    s[i].erase(iter);
    iter = lower_bound(s[j].begin(), s[j].end(), a[y]);
    s[j].erase(iter);
    s[i].push_back(a[y]);
    s[j].push_back(a[x]);
    sort(s[i].begin(), s[i].end());
    sort(s[j].begin(), s[j].end());
    swap(a[x], a[y]);
    cout << ans << endl;
  }
  return 0;
}
