#include <bits/stdc++.h>
using namespace std;
struct seica {
  vector<vector<long long>> bucket;
  vector<long long> dat;
  int n, m;
  seica(int n_) {
    n = n_;
    m = 1;
    while (m * m < n_) {
      m++;
    }
    dat.resize(m * m);
    bucket.resize(m);
  }
  void set(long long place, long long x) { dat[place] = x; }
  void make(long long place) {
    bucket[place].clear();
    for (long long i = place * m; i < (place + 1) * m; i++) {
      bucket[place].push_back(dat[i]);
    }
    sort(bucket[place].begin(), bucket[place].end());
  }
  long long bucket_que(long long place, long long k) {
    return lower_bound(bucket[place].begin(), bucket[place].end(), k) -
           bucket[place].begin();
  }
  long long que(long long l, long long r, long long k) {
    if (l >= r) {
      return 0;
    }
    long long ret = 0;
    for (long long(i) = (0); (i) < (m); ++i) {
      if (r <= i * m || l >= (i + 1) * m) {
        continue;
      } else if (i * m >= l && r >= (i + 1) * m) {
        ret += bucket_que(i, k);
      } else {
        for (long long j = i * m; j < (i + 1) * m; j++) {
          if (j < l || j >= r) continue;
          ret += (dat[j] <= k);
        }
      }
    }
    return ret;
  }
  void build() {
    for (long long(i) = (0); (i) < (m); ++i) {
      make(i);
    }
  }
};
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  long long n, q;
  cin >> n >> q;
  seica se(n);
  for (long long(i) = (0); (i) < (n); ++i) {
    se.set(i, i + 1);
  }
  se.build();
  long long ans = 0;
  for (long long(i) = (0); (i) < (q); ++i) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    if (a > b) {
      swap(a, b);
    }
    long long length = b - a - 1;
    long long aa = se.que(a + 1, b, se.dat[a]);
    long long bb = se.que(a + 1, b, se.dat[b]);
    ans += length - 2 * aa;
    ans += 2 * bb - length;
    if (se.dat[a] < se.dat[b]) {
      ans++;
    } else if (se.dat[a] > se.dat[b]) {
      ans--;
    }
    cout << ans << endl;
    swap(se.dat[a], se.dat[b]);
    se.make(a / se.m);
    se.make(b / se.m);
  }
  return 0;
}
