#include <bits/stdc++.h>
using namespace std;
struct fenwick {
  long long dat[205];
  void add(int pos, int val) {
    for (pos++; pos <= 200; pos += pos & -pos) dat[pos] += val;
  }
  long long query(int pos) {
    long long ret = 0;
    for (pos++; pos; pos -= pos & -pos) ret += dat[pos];
    return ret;
  }
};
int dat[200005];
int idx[200005];
fenwick bucket[205];
constexpr int BSIZE = 1000;
int n;
long long get_inversion_cnt(int val) {
  int bidx = idx[val] / BSIZE;
  int vidx = val / BSIZE;
  long long ret = 0;
  for (int j = 0; j < bidx; j++)
    ret += bucket[j].query(199) - bucket[j].query(vidx);
  for (int j = bidx + 1; j < (n + BSIZE - 1) / BSIZE; j++)
    ret += bucket[j].query(vidx - 1);
  for (int j = vidx * BSIZE; j < (vidx + 1) * BSIZE; j++) {
    if (j >= n) break;
    if (j == val) continue;
    if (idx[j] == -1) continue;
    if ((j < val) ^ (idx[j] < idx[val])) ++ret;
  }
  for (int j = bidx * BSIZE; j < (bidx + 1) * BSIZE; j++) {
    if (j >= n) break;
    int z = dat[j];
    if (vidx == z / BSIZE) continue;
    if (z == -1) continue;
    if ((j < idx[val]) ^ (z < val)) ++ret;
  }
  return ret;
}
int main() {
  int q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    dat[i] = i;
    idx[i] = i;
    bucket[i / BSIZE].add(i / BSIZE, 1);
  }
  long long invnow = 0;
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if (a == b) {
      printf("%lld\n", invnow);
      continue;
    }
    int va = dat[a];
    int vb = dat[b];
    invnow -= get_inversion_cnt(va);
    bucket[a / BSIZE].add(va / BSIZE, -1);
    idx[va] = -1;
    dat[a] = -1;
    invnow -= get_inversion_cnt(vb);
    bucket[b / BSIZE].add(vb / BSIZE, -1);
    idx[vb] = -1;
    dat[b] = -1;
    idx[va] = b;
    dat[b] = va;
    bucket[b / BSIZE].add(va / BSIZE, 1);
    invnow += get_inversion_cnt(va);
    idx[vb] = a;
    dat[a] = vb;
    bucket[a / BSIZE].add(vb / BSIZE, 1);
    invnow += get_inversion_cnt(vb);
    printf("%lld\n", invnow);
  }
}
