#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,inline,unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,abm,mmx,popcnt,tune=native")
using i64 = long long;
namespace IO {
char buf[1000000], *pa, *pb, pbuf[3000000], *pp = pbuf, stack_IO[21];
inline int read() {
  register int s = 0;
  register char c =
      pa == pb && (pb = (pa = buf) + fread(buf, 1, 1000000, stdin), pa == pb)
          ? EOF
          : *pa++;
  while (c != '-' && (c < '0' || c > '9'))
    c = pa == pb && (pb = (pa = buf) + fread(buf, 1, 1000000, stdin), pa == pb)
            ? EOF
            : *pa++;
  register int f = c == '-'
      ? c = pa == pb &&
                    (pb = (pa = buf) + fread(buf, 1, 1000000, stdin), pa == pb)
                ? EOF
                : *pa++,
               -1 : 1;
  while (c >= '0' && c <= '9')
    s = s * 10 + c - 48,
    c = pa == pb && (pb = (pa = buf) + fread(buf, 1, 1000000, stdin), pa == pb)
            ? EOF
            : *pa++;
  return s * f;
}
template <typename T>
inline void write(register T x, register char c = '\n') {
  if (x == 0) {
    *pp++ = 48, *pp++ = c;
    return;
  }
  if (x < 0) *pp++ = '-', x = ~x + 1;
  register char *top = stack_IO;
  while (x != 0) *top++ = x % 10 + 48, x /= 10;
  while (top != stack_IO) *pp++ = *--top;
  *pp++ = c;
}
void flush() { fwrite(pbuf, 1, pp - pbuf, stdout); }
template <typename T>
inline T abs(T x) {
  return x > 0 ? x : -x;
}
template <typename T>
inline int sgn(T x) {
  return x > 0 ? 1 : x < 0 ? -1 : 0;
}
template <typename T>
inline T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
inline T max(T x, T y) {
  return x > y ? x : y;
}
template <typename T>
inline void swap(T &x, T &y) {
  T tmp = x;
  x = y, y = tmp;
}
}  // namespace IO
using namespace IO;
const int MAXN = 200000, MAXQ = 50000;
int n, Q;
int seq[MAXN + 7];
namespace TIT {
struct SMT {
  struct Node {
    int siz;
    Node *left, *right;
    Node() {}
    Node(int _siz) : siz(_siz), left(NULL), right(NULL) {}
  } * root;
  void insert(int L, int X, int l, int r, Node *&now) {
    if (now == NULL) now = new Node(0);
    now->siz += X;
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (L <= mid)
      insert(L, X, l, mid, now->left);
    else
      insert(L, X, mid + 1, r, now->right);
  }
  void insert(int L, int X) { insert(L, X, 1, n, root); }
  int Count_Num(int L, int R, int l, int r, Node *now) {
    if (now == NULL) return 0;
    if (L <= l && r <= R) return now->siz;
    int mid = (l + r) >> 1;
    int res = 0;
    if (L <= mid) res += Count_Num(L, R, l, mid, now->left);
    if (mid < R) res += Count_Num(L, R, mid + 1, r, now->right);
    return res;
  }
  int Count_Num(int L, int R) { return Count_Num(L, R, 1, n, root); }
};
struct BIT {
  SMT smt[MAXN + 7];
  inline int lowbit(int x) { return x & (~x + 1); }
  void insert(int L, int X) {
    for (int i = L; i <= n; i += lowbit(i)) {
      smt[i].insert(X, 1);
    }
  }
  void erase(int L, int X) {
    for (int i = L; i <= n; i += lowbit(i)) {
      smt[i].insert(X, -1);
    }
  }
  int Count_Num(int L, int R, int LX, int RX) {
    if (L > R || LX > RX) return 0;
    int res = 0;
    for (int i = R; i >= 1; i -= lowbit(i)) res += smt[i].Count_Num(LX, RX);
    for (int i = L - 1; i >= 1; i -= lowbit(i)) res -= smt[i].Count_Num(LX, RX);
    return res;
  }
} bit;
void build() {
  for (int i = 1; i <= n; ++i) {
    bit.insert(i, i);
  }
}
}  // namespace TIT
void input() {
  n = read(), Q = read();
  for (register int i = 1; i <= n; ++i) {
    seq[i] = i;
  }
  TIT::build();
}
void solve() {
  i64 res = 0;
  while (Q--) {
    int l = read(), r = read();
    res -= TIT::bit.Count_Num(1, l - 1, seq[l] + 1, n);
    res -= TIT::bit.Count_Num(l + 1, n, 1, seq[l] - 1);
    TIT::bit.erase(l, seq[l]);
    res -= TIT::bit.Count_Num(1, r - 1, seq[r] + 1, n);
    res -= TIT::bit.Count_Num(r + 1, n, 1, seq[r] - 1);
    TIT::bit.erase(r, seq[r]);
    swap(seq[l], seq[r]);
    res += TIT::bit.Count_Num(1, l - 1, seq[l] + 1, n);
    res += TIT::bit.Count_Num(l + 1, n, 1, seq[l] - 1);
    TIT::bit.insert(l, seq[l]);
    res += TIT::bit.Count_Num(1, r - 1, seq[r] + 1, n);
    res += TIT::bit.Count_Num(r + 1, n, 1, seq[r] - 1);
    TIT::bit.insert(r, seq[r]);
    write(res);
  }
}
void Main() {
  input();
  solve();
  flush();
}
int main() {
  Main();
  return 0;
}
