#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100, sq = 250, inf = 1e9 + 100, mod = 1e9 + 7;
int n, a[maxn], b[maxn];
int zap;
pair<int, int> zaps[maxn];
long long answer;
bool good[maxn];
pair<int, int> q[maxn];
bool bad[maxn];
int p[maxn];
int g[maxn], sz;
int fen[maxn];
void inc(int i) {
  for (; i < n; i = (i | (i + 1))) fen[i]++;
}
int sum(int i) {
  int ret = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) ret += fen[i];
  return ret;
}
vector<pair<int, pair<int, int> > > que[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> zap;
  for (int i = 0; i < n; i++) a[i] = i;
  for (int i = 0; i < zap; i++) {
    cin >> zaps[i].first >> zaps[i].second, zaps[i].first--, zaps[i].second--;
    if (zaps[i].first > zaps[i].second) swap(zaps[i].first, zaps[i].second);
  }
  for (int st = 0; st < zap; st += sq) {
    for (int i = 0; i < n; i++)
      b[i] = a[i], bad[i] = 0, fen[i] = 0, que[i].clear();
    int l = st, r = min(zap, st + sq) - 1;
    for (int i = l; i <= r; i++) {
      bad[zaps[i].first] = 1;
      bad[zaps[i].second] = 1;
      q[i] = make_pair(b[zaps[i].first], b[zaps[i].second]);
      que[zaps[i].first].push_back(
          make_pair(b[zaps[i].second], make_pair(i, -1)));
      que[zaps[i].second].push_back(
          make_pair(b[zaps[i].second], make_pair(i, 1)));
      que[zaps[i].first].push_back(
          make_pair(b[zaps[i].first], make_pair(i, 1)));
      que[zaps[i].second].push_back(
          make_pair(b[zaps[i].first], make_pair(i, -1)));
      swap(b[zaps[i].first], b[zaps[i].second]);
      p[i] = 0;
    }
    sz = 0;
    for (int i = 0; i < n; i++)
      if (bad[i]) g[sz] = i, sz++;
    for (int i = 0; i < n; i++)
      if (!bad[i])
        inc(a[i]);
      else
        for (int j = 0; j < que[i].size(); j++)
          p[que[i][j].second.first] +=
              que[i][j].second.second * sum(que[i][j].first - 1);
    int cnt = r - l + 1;
    for (int j = l; j <= r; j++) {
      p[j] *= 2;
      int x = zaps[j].first, y = zaps[j].second;
      for (int i = 0; i < sz; i++)
        if (x < g[i] && g[i] < y) {
          if (min(a[x], a[y]) < a[g[i]] && a[g[i]] < max(a[x], a[y]))
            if (a[x] < a[g[i]])
              p[j] += 2;
            else
              p[j] -= 2;
        }
      if (a[x] < a[y])
        p[j]++;
      else
        p[j]--;
      if (x != y) answer += (long long)p[j];
      swap(a[x], a[y]);
      cout << answer << '\n';
    }
  }
}
