#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
typedef struct node {
  int val, prior, size;
  struct node *l, *r;
} node;
typedef node *pnode;
int sz(pnode t) { return t ? t->size : 0; }
void upd_sz(pnode t) {
  if (t) t->size = sz(t->l) + 1 + sz(t->r);
}
void split(pnode t, pnode &l, pnode &r, int key) {
  if (!t)
    l = r = NULL;
  else if (t->val <= key)
    split(t->r, t->r, r, key), l = t;
  else
    split(t->l, l, t->l, key), r = t;
  upd_sz(t);
}
void merge(pnode &t, pnode l, pnode r) {
  if (!l || !r)
    t = l ? l : r;
  else if (l->prior > r->prior)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
  upd_sz(t);
}
void insert(pnode &t, pnode it) {
  if (!t)
    t = it;
  else if (it->prior > t->prior)
    split(t, it->l, it->r, it->val), t = it;
  else
    insert(t->val <= it->val ? t->r : t->l, it);
  upd_sz(t);
}
void erase(pnode &t, int key) {
  if (!t)
    return;
  else if (t->val == key) {
    pnode temp = t;
    merge(t, t->l, t->r);
    free(temp);
  } else
    erase(t->val < key ? t->r : t->l, key);
  upd_sz(t);
}
pnode init(int val) {
  pnode ret = new node();
  ret->val = val;
  ret->size = 1;
  ret->prior = rand();
  ret->l = ret->r = NULL;
  return ret;
}
bool search(pnode n, int k) {
  if (!n) return false;
  if (n->val == k) return 1;
  if (k > n->val) return search(n->r, k);
  return search(n->l, k);
}
int findKth(pnode n, int k) {
  if (!n) return 10000000000ll;
  if (sz(n) < k) return 10000000000ll;
  if (sz(n) == 1 || 1 + sz(n->l) == k) return n->val;
  if (sz(n->l) >= k)
    return findKth(n->l, k);
  else
    return findKth(n->r, k - sz(n->l) - 1);
}
int lessT(pnode n, int k) {
  if (!n) return 0;
  if (n->val >= k)
    return lessT(n->l, k);
  else
    return 1 + sz(n->l) + lessT(n->r, k);
}
int greaterT(pnode n, int k) {
  if (!n) return 0;
  if (n->val <= k)
    return greaterT(n->r, k);
  else
    return 1 + sz(n->r) + greaterT(n->l, k);
}
pnode tree[4 * N];
void print(pnode n) {
  if (!n) return;
  cout << n->val << " ";
  print(n->l);
  print(n->r);
}
void upd(int i, int s, int e, int p, int v, bool f) {
  if (s > p || e < p) return;
  if (f) {
    insert(tree[i], init(v));
  } else {
    erase(tree[i], v);
  }
  if (s >= p && e <= p) return;
  int mid = (s + e) >> 1;
  upd(i << 1, s, mid, p, v, f);
  upd(i << 1 | 1, mid + 1, e, p, v, f);
}
int qur(int i, int s, int e, int s1, int e1, int v, bool f) {
  if (s > e1 || e < s1) return 0;
  if (s >= s1 && e <= e1) {
    return f ? greaterT(tree[i], v) : lessT(tree[i], v);
  }
  int mid = (s + e) >> 1;
  return qur(i << 1, s, mid, s1, e1, v, f) +
         qur(i << 1 | 1, mid + 1, e, s1, e1, v, f);
}
int a[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long long res = 0;
  memset(tree, 0, sizeof tree);
  for (int i = 0; i < n; i++) {
    a[i] = i;
    upd(1, 0, n - 1, i, i, 1);
  }
  int x, y;
  while (m--) {
    scanf("%d%d", &x, &y);
    if (x > y) swap(x, y);
    x--;
    y--;
    if (a[x] > a[y])
      res--;
    else if (a[x] < a[y])
      res++;
    if (y - x > 1) {
      res -= qur(1, 0, n - 1, x + 1, y - 1, a[x], 0);
      res += qur(1, 0, n - 1, x + 1, y - 1, a[x], 1);
      res -= qur(1, 0, n - 1, x + 1, y - 1, a[y], 1);
      res += qur(1, 0, n - 1, x + 1, y - 1, a[y], 0);
    }
    upd(1, 0, n - 1, x, a[x], 0);
    upd(1, 0, n - 1, x, a[y], 1);
    upd(1, 0, n - 1, y, a[y], 0);
    upd(1, 0, n - 1, y, a[x], 1);
    swap(a[x], a[y]);
    printf("%I64d\n", res);
  }
}
