#include <bits/stdc++.h>
using namespace std;
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT &...rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
int N, BCNT, BSZ, Q;
int A[300010 + 100];
int BLOCK[888][888];
int n;
int bucket[1 << 8], temp[300010 + 10];
void radix_sort(int *ar, int n) {
  int i, j, x;
  const int bitmask = (1 << 8) - 1;
  for (i = 0; i < 24; i += 8) {
    memset(bucket, 0, sizeof(bucket));
    for (j = 0; j < n; j++) bucket[(ar[j] >> i) & bitmask]++;
    for (j = 1; j <= bitmask; j++) {
      bucket[j] += bucket[j - 1];
    }
    for (j = n - 1; j >= 0; j--) temp[--bucket[(ar[j] >> i) & bitmask]] = ar[j];
    for (j = 0; j < n; j++) ar[j] = temp[j];
  }
}
void build(int idx) {
  int st = idx * BSZ;
  int ed = (idx + 1) * BSZ;
  for (int i = st, j = 0; i < ed; i++, j++) {
    BLOCK[idx][j] = A[i];
  }
  radix_sort(BLOCK[idx], BSZ);
}
int get(int idx, int K) {
  int up = upper_bound(BLOCK[idx], BLOCK[idx] + BSZ, K) - BLOCK[idx];
  return (BSZ - up);
}
int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 0; i < N; i++) {
    A[i] = i + 1;
  }
  BSZ = 800;
  BCNT = (N / BSZ) + (N % BSZ != 0);
  for (int i = 0; i < BCNT; i++) {
    build(i);
  }
  long long ans = 0;
  for (int j = 0; j < Q; j++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x != y) {
      if (x > y) swap(x, y);
      int i = x;
      int k1 = A[x - 1], k2 = A[y - 1];
      long long a1 = 0, a2 = 0;
      for (; i % BSZ != 0 && i <= y - 2; i++) {
        a1 += (A[i] > k1);
        a2 += (A[i] > k2);
      }
      for (; i + BSZ <= y - 2; i += BSZ) {
        a1 += get(i / BSZ, k1);
        a2 += get(i / BSZ, k2);
      }
      for (; i <= y - 2; i++) {
        a1 += (A[i] > k1);
        a2 += (A[i] > k2);
      }
      long long rg = (y - x - 1);
      ans += +a1 - (rg - a1);
      ans += -a2 + (rg - a2);
      if (A[x - 1] < A[y - 1])
        ans += 1;
      else
        ans -= 1;
      swap(A[x - 1], A[y - 1]);
      build((x - 1) / BSZ);
      build((y - 1) / BSZ);
    }
    printf("%lld\n", ans);
  }
}
