#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int64_t fx[4] = {0, 1, 0, -1};
int64_t fy[4] = {1, 0, -1, 0};
const long long M = 2e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7, mod = 998244353;
const long long MC = (1 << 22) + 5;
vector<int64_t> all[455];
int64_t bsize = 450;
int64_t ara[M], bid[M];
void precomp() {}
void solve() {
  int64_t n, q;
  cin >> n >> q;
  for (int64_t i = 0, bnum; i < n; i++) {
    bnum = i / bsize;
    ara[i] = i + 1;
    all[bnum].push_back(i + 1);
    bid[ara[i]] = i % bsize;
  }
  for (int64_t i = 0; i < 450; i++) {
    sort(all[i].begin(), all[i].end());
  }
  int64_t ans = 0;
  while (q--) {
    int64_t l, r;
    cin >> l >> r;
    if (l == r) {
      cout << ans << endl;
      continue;
    }
    --l, --r;
    if (l > r) swap(l, r);
    int64_t lval = ara[l], rval = ara[r], mul = 1;
    if (lval > rval) {
      mul = -1;
      swap(lval, rval);
    }
    int64_t lb = l / bsize, rb = r / bsize;
    int64_t c = 0;
    for (int64_t i = lb + 1; i <= rb - 1; i++) {
      c += (int64_t)(upper_bound(all[i].begin(), all[i].end(), rval) -
                     all[i].begin());
      c -= (int64_t)(upper_bound(all[i].begin(), all[i].end(), lval) -
                     all[i].begin());
    }
    for (int64_t i = l + 1; i < min((lb + 1) * bsize, r); i++) {
      if (ara[i] > lval && ara[i] < rval) {
        c++;
      }
    }
    for (int64_t i = r - 1; i >= max(l + 1, ((rb)*bsize)); i--) {
      if (ara[i] > lval && ara[i] < rval) c++;
    }
    if (lb != rb) c = c * 2;
    c += 1;
    ans += mul * c;
    cout << ans << endl;
    int64_t lid = bid[ara[l]];
    all[lb].erase(all[lb].begin() + lid);
    int64_t rid = bid[ara[r]];
    if (lb == rb && lid <= rid) rid--;
    all[rb].erase(all[rb].begin() + rid);
    all[lb].push_back(ara[r]);
    all[rb].push_back(ara[l]);
    sort(all[lb].begin(), all[lb].end());
    sort(all[rb].begin(), all[rb].end());
    for (int64_t i = 0; i < all[lb].size(); i++) bid[all[lb][i]] = i;
    for (int64_t i = 0; i < all[rb].size(); i++) bid[all[rb][i]] = i;
    swap(ara[l], ara[r]);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  precomp();
  solve();
  return 0;
}
