#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 452;
int n, m, block, cnt, belong[N], a[N], L[M], R[M];
vector<int> c[M];
inline void build() {
  for (int i = 1; i <= n; ++i) belong[i] = (i - 1) / block + 1, a[i] = i;
  for (int i = 1; i <= n; i += block)
    L[++cnt] = i, R[cnt] = std::min(n, i + block - 1);
  for (int i = 1; i <= n; ++i) c[belong[i]].push_back(i);
}
inline void update(int l, int r) {
  int x = belong[l], y = belong[r];
  c[x].erase(lower_bound(c[x].begin(), c[x].end(), a[l]));
  c[x].insert(upper_bound(c[x].begin(), c[x].end(), a[r]), a[r]);
  c[y].erase(lower_bound(c[y].begin(), c[y].end(), a[r]));
  c[y].insert(upper_bound(c[y].begin(), c[y].end(), a[l]), a[l]);
  std::swap(a[l], a[r]);
}
inline long long query(int l, int r, int k) {
  if (l > r) return 0;
  int x = belong[l], y = belong[r], ans = 0;
  if (x == y) {
    for (int i = l; i <= r; ++i)
      if (a[i] < k) ++ans;
    return ans;
  }
  for (int i = l; i <= R[x]; ++i)
    if (a[i] < k) ++ans;
  for (int i = L[y]; i <= r; ++i)
    if (a[i] < k) ++ans;
  for (int i = x + 1; i < y; ++i) {
    int tmp = upper_bound(c[i].begin(), c[i].end(), k) - c[i].begin();
    ans += tmp;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  block = sqrt(n);
  build();
  long long ans = 0;
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x > y) std::swap(x, y);
    if (x == y)
      printf("%lld\n", ans);
    else {
      long long sub = query(x + 1, y - 1, a[x]);
      long long add = y - x - sub - 1;
      ans += add - sub;
      add = query(x + 1, y - 1, a[y]);
      sub = y - x - add - 1;
      ans += add - sub;
      ans += a[x] < a[y] ? 1 : -1;
      printf("%lld\n", ans);
      update(x, y);
    }
  }
  return 0;
}
