#include <bits/stdc++.h>
using namespace std;
int tot, a[200010], b[200010], BIT[200010], L[465], R[465], belong[200010],
    cc[200010], h[200010];
int read() {
  int s = 0, fh = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + (ch - '0');
    ch = getchar();
  }
  return s * fh;
}
void cl(int k) {
  int ll = L[k], rr = R[k], i;
  for (i = ll; i <= rr; i++) b[i] = a[i];
  sort(b + ll, b + rr + 1);
}
int Lowbit(int k) { return k & (-k); }
void Update(int k1, int k2) {
  while (k1 <= tot) {
    BIT[k1] += k2;
    k1 += Lowbit(k1);
  }
}
int Sum(int k1) {
  int sum = 0;
  while (k1 > 0) {
    sum += BIT[k1];
    k1 -= Lowbit(k1);
  }
  return sum;
}
int ef1(int k, int v) {
  int l = L[k], r = R[k], mid, ans = -1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (b[mid] < v) {
      ans = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  if (ans == -1)
    return 0;
  else
    return ans - L[k] + 1;
}
int ef2(int k, int v) {
  int l = L[k], r = R[k], mid, ans = -1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (b[mid] > v) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  if (ans == -1)
    return 0;
  else
    return R[k] - ans + 1;
}
int GET1(int l, int r, int v) {
  if (l > r) return 0;
  int ll = belong[l], rr = belong[r], i, tot = 0;
  if (ll == rr) {
    for (i = l; i <= r; i++)
      if (a[i] < v) tot++;
    return tot;
  }
  for (i = l; i <= R[ll]; i++)
    if (a[i] < v) tot++;
  for (i = ll + 1; i <= rr - 1; i++) tot += ef1(i, v);
  for (i = L[rr]; i <= r; i++)
    if (a[i] < v) tot++;
  return tot;
}
int GET2(int l, int r, int v) {
  if (l > r) return 0;
  int ll = belong[l], rr = belong[r], i, tot = 0;
  if (ll == rr) {
    for (i = l; i <= r; i++)
      if (a[i] > v) tot++;
    return tot;
  }
  for (i = l; i <= R[ll]; i++)
    if (a[i] > v) tot++;
  for (i = ll + 1; i <= rr - 1; i++) tot += ef2(i, v);
  for (i = L[rr]; i <= r; i++)
    if (a[i] > v) tot++;
  return tot;
}
int main() {
  int n, i, lcc, block, M, m, s1, s2;
  long long ans = 0LL;
  n = read();
  for (i = 1; i <= n; i++) a[i] = i;
  block = (int)sqrt(n);
  if (n % block == 0)
    M = n / block;
  else
    M = n / block + 1;
  for (i = 1; i <= n; i++) belong[i] = (i - 1) / block + 1;
  for (i = 1; i <= M; i++) {
    L[i] = (i - 1) * block + 1;
    R[i] = min(i * block, n);
  }
  for (i = 1; i <= M; i++) cl(i);
  ans = 0LL;
  for (i = n; i >= 1; i--) {
    ans += (long long)Sum(a[i] - 1);
    Update(a[i], 1);
  }
  m = read();
  for (i = 1; i <= m; i++) {
    s1 = read();
    s2 = read();
    if (s1 > s2) swap(s1, s2);
    if (a[s1] > a[s2])
      ans--;
    else if (a[s1] < a[s2])
      ans++;
    ans = ans - (long long)GET1(s1 + 1, s2 - 1, a[s1]) +
          (long long)GET2(s1 + 1, s2 - 1, a[s1]);
    ans = ans - (long long)GET2(s1 + 1, s2 - 1, a[s2]) +
          (long long)GET1(s1 + 1, s2 - 1, a[s2]);
    swap(a[s1], a[s2]);
    cl(belong[s1]);
    cl(belong[s2]);
    printf("%lld\n", ans);
  }
  fclose(stdin);
  fclose(stdout);
  return 0;
}
