#include <bits/stdc++.h>
using namespace std;
constexpr long long N = 2e5 + 9, B = 500;
vector<long long> sted[B];
long long n, m, a[N], ans;
long long ichmin(long long id, long long tar) {
  return upper_bound(sted[id].begin(), sted[id].end(), tar) - sted[id].begin();
}
long long chkmin(long long l, long long r, long long tar) {
  if (l > r) return 0;
  long long L = l / B, R = r / B, ret = 0;
  if (L == R)
    while (l <= r) ret += a[l++] < tar;
  else {
    ++L, --R;
    while (l / B < L) ret += a[l++] < tar;
    while (r / B > R) ret += a[r--] < tar;
    while (L <= R) ret += ichmin(L++, tar);
  }
  return ret;
}
void resort(long long id, long long src, long long dst) {
  for (long long pos = 0; pos < B; ++pos)
    if (sted[id][pos] == src) {
      sted[id][pos] = dst;
      while (pos - 1 >= 0 && sted[id][pos] < sted[id][pos - 1])
        swap(sted[id][pos], sted[id][pos - 1]), --pos;
      while (pos + 1 < B && sted[id][pos] > sted[id][pos + 1])
        swap(sted[id][pos], sted[id][pos + 1]), ++pos;
      break;
    }
}
void swapcalc(long long l, long long r) {
  if (l == r) return;
  if (l > r) swap(l, r);
  ans += (chkmin(l + 1, r - 1, a[r]) - chkmin(l + 1, r - 1, a[l])) * 2;
  a[l] < a[r] ? ++ans : --ans;
  swap(a[l], a[r]);
  long long L = l / B, R = r / B;
  if (L == R) return;
  resort(L, a[r], a[l]), resort(R, a[l], a[r]);
}
signed main() {
  cin >> n >> m;
  n = (n + B - 1) / B * B;
  for (long long i = 0; i < n; ++i) sted[i / B].push_back(a[i] = i);
  for (long long l, r; m; --m) {
    cin >> l >> r, swapcalc(l - 1, r - 1), cout << ans << endl;
  }
  return 0;
}
