Problem: Anton likes permutations, especially he likes to permute their elements. Note that a permutation of n elements is a sequence of numbers {a1, a2, ..., an}, in which every number from 1 to n appears exactly once.

One day Anton got a new permutation and started to play with it. He does the following operation q times: he takes two elements of the permutation and swaps these elements. After each operation he asks his friend Vanya, how many inversions there are in the new permutation. The number of inversions in a permutation is the number of distinct pairs (i, j) such that 1 ≤ i < j ≤ n and ai > aj.

Vanya is tired of answering Anton's silly questions. So he asked you to write a program that would answer these questions instead of him.

Initially Anton's permutation was {1, 2, ..., n}, that is ai = i for all i such that 1 ≤ i ≤ n.

Input

The first line of the input contains two integers n and q (1 ≤ n ≤ 200 000, 1 ≤ q ≤ 50 000) — the length of the permutation and the number of operations that Anton does.

Each of the following q lines of the input contains two integers li and ri (1 ≤ li, ri ≤ n) — the indices of elements that Anton swaps during the i-th operation. Note that indices of elements that Anton swaps during the i-th operation can coincide. Elements in the permutation are numbered starting with one.

Output

Output q lines. The i-th line of the output is the number of inversions in the Anton's permutation after the i-th operation.

Examples

Input

5 4
4 5
2 4
2 5
2 2


Output

1
4
3
3


Input

2 1
2 1


Output

1


Input

6 7
1 4
3 5
2 3
3 3
3 6
2 1
5 1


Output

5
6
7
7
10
11
8

Note

Consider the first sample.

After the first Anton's operation the permutation will be {1, 2, 3, 5, 4}. There is only one inversion in it: (4, 5).

After the second Anton's operation the permutation will be {1, 5, 3, 2, 4}. There are four inversions: (2, 3), (2, 4), (2, 5) and (3, 4).

After the third Anton's operation the permutation will be {1, 4, 3, 2, 5}. There are three inversions: (2, 3), (2, 4) and (3, 4).

After the fourth Anton's operation the permutation doesn't change, so there are still three inversions.

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.Random;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jialin Ouyang (Jialin.Ouyang@gmail.com)
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    QuickScanner in = new QuickScanner(inputStream);
    QuickWriter out = new QuickWriter(outputStream);
    TaskE solver = new TaskE();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskE {
    int n;
    int q;
    int[] perm;
    int[] permIdx;
    int[] lower;
    int[] upper;
    QuickWriter out;
    int sqrtQ;
    int sqrtQ2;
    int[] nxtMobileIdx;
    IntArrayList mobileIdx;
    IntArrayList mobileValue;
    int[][] forward;
    int[][] backward;
    long res;
    int m;

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      this.out = out;
      n = in.nextInt();
      q = in.nextInt();
      perm = new int[n];
      permIdx = new int[n];
      for (int i = 0; i < n; ++i) {
        perm[i] = i;
        permIdx[i] = i;
      }
      lower = new int[q];
      upper = new int[q];
      for (int i = 0; i < q; ++i) {
        lower[i] = in.nextInt() - 1;
        upper[i] = in.nextInt() - 1;
      }
      calc();
    }

    void calc() {
      sqrtQ = 1;
      for (; sqrtQ * sqrtQ < q; ++sqrtQ) {
      }
      sqrtQ2 = sqrtQ << 1;
      nxtMobileIdx = new int[n];
      mobileIdx = new IntArrayList(sqrtQ2);
      mobileValue = new IntArrayList(sqrtQ2);
      forward = new int[sqrtQ2][sqrtQ2];
      backward = new int[sqrtQ2][sqrtQ2];
      res = 0;
      for (int fromIdx = 0, toIdx = sqrtQ; fromIdx < q; fromIdx += sqrtQ, toIdx += sqrtQ) {
        calc(fromIdx, Math.min(toIdx, q));
      }
    }

    void calc(int fromIdx, int toIdx) {
      mobileIdx.clear();
      for (int i = fromIdx; i < toIdx; ++i) {
        mobileIdx.add(lower[i]);
        mobileIdx.add(upper[i]);
      }
      mobileIdx.sortAndUnique();
      mobileValue.clear();
      for (int i = 0; i < mobileIdx.size; ++i) {
        mobileValue.add(perm[mobileIdx.get(i)]);
      }
      mobileValue.sort();
      m = mobileValue.size;
//System.out.printf("====[%d, %d)====\n", fromIdx, toIdx);
//System.out.printf("\tmobileId:%s\n", mobileIdx.toString());
//System.out.printf("\tmobileValue:%s\n", mobileValue.toString());
//System.out.printf("\tperm:%s\n", IntArrayUtils.toString(perm));
//System.out.printf("\tpermIdx:%s\n", IntArrayUtils.toString(permIdx));
      calcForward();
      calcBackward();
      for (int i = fromIdx; i < toIdx; ++i) {
        res -= calcInvs(lower[i], upper[i]);
        swap(lower[i], upper[i]);
        res += calcInvs(lower[i], upper[i]);
        out.println(res);
      }
    }

    void calcForward() {
      Arrays.fill(nxtMobileIdx, -1);
      for (int i = 0; i < m; ++i) {
        nxtMobileIdx[mobileIdx.get(i)] = i;
        Arrays.fill(forward[i], 0, m, 0);
      }
      for (int i = n - 2; i >= 0; --i)
        if (nxtMobileIdx[i] < 0) {
          nxtMobileIdx[i] = nxtMobileIdx[i + 1];
        }
//System.out.printf("\tnxtMobileIdx:%s\n", IntArrayUtils.toString(nxtMobileIdx, 0, n));
//for (int i = 0; i < m; ++i) System.out.printf("\t%s\n", IntArrayUtils.toString(forward[i], 0, m));
      int from = n, to;
      for (int i = m - 1; i >= 0; --i) {
        to = from;
        from = mobileValue.get(i);
        for (int j = from + 1; j < to; ++j) {
          int idx = permIdx[j];
          int nxtIdx = nxtMobileIdx[idx];
//if (idx == nxtIdx) System.out.printf("\t+ value:%d idx:%d [nxtIdx:%d][i:%d]\n", j, idx, nxtIdx, i);
          if (nxtIdx >= 0) {
            ++forward[nxtIdx][i];
          }
        }
      }
      for (int i = 0; i < m; ++i)
        for (int j = m - 1; j >= 0; --j) {
          if (i > 0) forward[i][j] += forward[i - 1][j];
          if (j + 1 < m) forward[i][j] += forward[i][j + 1];
          if (i > 0 && j + 1 < m) forward[i][j] -= forward[i - 1][j + 1];
        }
//System.out.printf("\tforward\n");
//for (int i = 0; i < m; ++i) System.out.printf("\t%s\n", IntArrayUtils.toString(forward[i], 0, m));
    }

    void calcBackward() {
      Arrays.fill(nxtMobileIdx, -1);
      for (int i = 0; i < m; ++i) {
        nxtMobileIdx[mobileIdx.get(i)] = i;
        Arrays.fill(backward[i], 0, m, 0);
      }
      for (int i = 1; i < n; ++i)
        if (nxtMobileIdx[i] < 0) {
          nxtMobileIdx[i] = nxtMobileIdx[i - 1];
        }
//System.out.printf("\tnxtMobileIdx:%s\n", IntArrayUtils.toString(nxtMobileIdx, 0, n));
//for (int i = 0; i < m; ++i) System.out.printf("\t%s\n", IntArrayUtils.toString(forward[i], 0, m));
      int from, to = -1;
      for (int i = 0; i < m; ++i) {
        from = to;
        to = mobileValue.get(i);
        for (int j = from + 1; j < to; ++j) {
          int idx = permIdx[j];
          int nxtIdx = nxtMobileIdx[idx];
          if (nxtIdx >= 0) {
//System.out.printf("\t+ value:%d idx:%d [nxtIdx:%d][i:%d]\n", j, idx, nxtIdx, i);
            ++backward[nxtIdx][i];
          }
        }
      }
      for (int i = m - 1; i >= 0; --i)
        for (int j = 0; j < m; ++j) {
          if (i + 1 < m) backward[i][j] += backward[i + 1][j];
          if (j > 0) backward[i][j] += backward[i][j - 1];
          if (i + 1 < m && j > 0) backward[i][j] -= backward[i + 1][j - 1];
        }
//System.out.printf("\tbackward\n");
//for (int i = 0; i < m; ++i) System.out.printf("\t%s\n", IntArrayUtils.toString(backward[i], 0, m));
    }

    int calcInvs(int lower, int upper) {
      return calcInv(lower, perm[lower])
          + calcInv(upper, perm[upper])
          - (perm[Math.min(lower, upper)] > perm[Math.max(lower, upper)] ? 1 : 0);
    }

    int calcInv(int oldIdx, int oldValue) {
      int idx = mobileIdx.lowerBound(oldIdx);
      int value = mobileValue.lowerBound(oldValue);
      int res = forward[idx][value] + backward[idx][value];
      for (int i = 0; i < idx; ++i)
        if (perm[mobileIdx.get(i)] > oldValue) {
          ++res;
        }
      for (int i = idx + 1; i < mobileIdx.size; ++i)
        if (oldValue > perm[mobileIdx.get(i)]) {
          ++res;
        }
      return res;
    }

    void swap(int lower, int upper) {
      IntArrayUtils.swap(perm, lower, upper);
      permIdx[perm[lower]] = lower;
      permIdx[perm[upper]] = upper;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public QuickWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void print(Object... objects) {
      for (int i = 0; i < objects.length; ++i) {
        if (i > 0) {
          writer.print(' ');
        }
        writer.print(objects[i]);
      }
    }

    public void println(Object... objects) {
      print(objects);
      writer.print('\n');
    }

    public void close() {
      writer.close();
    }

  }

  static class IntArrayList implements IntCollection {
    private static final int[] EMPTY = {};
    public int[] values;
    public int size;

    public IntArrayList() {
      values = EMPTY;
      clear();
    }

    public IntArrayList(int capacity) {
      values = new int[IntUtils.nextPow2(capacity)];
      clear();
    }

    public IntArrayList(Collection<Integer> collection) {
      this(collection.size());
      addAll(collection);
    }


    public void clear() {
      size = 0;
    }


    public void add(int value) {
      ensureCapacity(size + 1);
      addInternal(value);
    }


    public void addAll(Collection<Integer> values) {
      ensureCapacity(size + values.size());
      for (int value : values) {
        addInternal(value);
      }
    }

    public int get(int idx) {
      if (idx >= size) throw new ArrayIndexOutOfBoundsException();
      return values[idx];
    }

    public void sort() {
      IntArrayUtils.sort(values, 0, size);
    }

    public void unique() {
      size = IntArrayUtils.unique(values, 0, size);
    }

    public void sortAndUnique() {
      sort();
      unique();
    }

    public int lowerBound(int value) {
      return IntArrayUtils.lowerBound(values, 0, size, value);
    }


    public String toString() {
      return IntArrayUtils.toString(values, 0, size);
    }

    public void ensureCapacity(int capacity) {
      if (capacity <= values.length) return;
      int[] newValues = new int[IntUtils.nextPow2(capacity)];
      for (int i = 0; i < size; ++i) {
        newValues[i] = values[i];
      }
      values = newValues;
    }

    private void addInternal(int value) {
      values[size++] = value;
    }

  }

  static class IntArrayUtils {
    private static final Random RANDOM = new Random(1000000007);

    public static int unique(int[] values, int fromIdx, int toIdx) {
      if (fromIdx == toIdx) return 0;
      int res = 1;
      for (int i = fromIdx + 1; i < toIdx; ++i) {
        if (values[i - 1] != values[i]) {
          values[fromIdx + res++] = values[i];
        }
      }
      return res;
    }

    public static void sort(int[] values, int fromIdx, int toIdx) {
      shuffle(values, fromIdx, toIdx);
      Arrays.sort(values, fromIdx, toIdx);
    }

    public static int lowerBound(int[] values, int fromIdx, int toIdx, int value) {
      int res = toIdx;
      for (int lower = fromIdx, upper = toIdx - 1; lower <= upper; ) {
        int medium = (lower + upper) >> 1;
        if (value <= values[medium]) {
          res = medium;
          upper = medium - 1;
        } else {
          lower = medium + 1;
        }
      }
      return res;
    }

    public static void swap(int[] values, int uIdx, int vIdx) {
      if (uIdx == vIdx) return;
      values[uIdx] ^= values[vIdx];
      values[vIdx] ^= values[uIdx];
      values[uIdx] ^= values[vIdx];
    }

    public static void shuffle(int[] values, int fromIdx, int toIdx) {
      for (int i = toIdx - fromIdx - 1; i > 0; --i) {
        swap(values, i + fromIdx, RANDOM.nextInt(i + 1) + fromIdx);
      }
    }

    public static String toString(int[] values, int fromIdx, int toIdx) {
      StringBuilder sb = new StringBuilder("[");
      for (int i = fromIdx; i < toIdx; ++i) {
        if (i != fromIdx) sb.append(", ");
        sb.append(values[i]);
      }
      return sb.append("]").toString();
    }

  }

  static interface IntCollection {
  }

  static class IntUtils {
    public static boolean isPow2(int n) {
      return n > 0 && (n & (n - 1)) == 0;
    }

    public static int nextPow2(int n) {
      if (n < 1) return 1;
      return isPow2(n) ? n : Integer.highestOneBit(n) << 1;
    }

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + c - '0';
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }
}