class Node {
  next; key;
  constructor(key, MAX_LAYER) {
    this.key = key;
    this.next = Array(MAX_LAYER);
  }
}

class SkipList {
  head; MAX_LAYER; maxNode;
  constructor(MAX_LAYER = 3) {
    this.MAX_LAYER = MAX_LAYER;
    this.head = new Node(-1e10, MAX_LAYER);
    for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;
  }

  insert(key) {
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = new Node(key);
    if (this.maxNode && this.maxNode.key < key) this.maxNode = node;
    node.next[0] = cur.next[0];
    cur.next[0] = node;
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = node.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (Math.random() < 0.5) break;
      while (cur.next[i] === undefined) {
        cur = trace.pop();
      }
      node.next[i] = cur.next[i];
      cur.next[i] = node;
    }
    return [prevNode, nextNode];
  }

  remove(key) {
    if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = cur.next[0];
    if (!node || node.key != key) return;
    cur.next[0] = node.next[0];
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = cur.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (node.next[i] === undefined) break;
      while (cur.next[i] != node) {
        cur = trace.pop();
      }
      cur.next[i] = node.next[i];
    }
    return [prevNode, nextNode];
  }

  min() {
    return (this.head.next[0] || {}).key;
  }

  max() {
    if (this.maxNode) return this.maxNode.key;
    var cur = this.head;
    for (let i = this.MAX_LAYER - 1; i >= 0; i--) {
      while (cur.next[i]) cur = cur.next[i];
    }
    if (cur != this.head) this.maxNode = cur;
    return cur != this.head ? cur.key : undefined;
  }

  print() {
    for (let i = 0; i < this.MAX_LAYER; i++) {
      let arr = [];
      let cur = this.head.next[i];
      while (cur) {
        arr.push(cur.key);
        cur = cur.next[i];
      }
      console.log(`Layer ${i}: ${arr.join(' ')}`)
    }
  }
}

// var t = Date.now();
// var sk = new SkipList(20);
// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);
// arr.forEach(v => sk.insert(v));
// console.log(Date.now() - t);
// arr.forEach(v => sk.remove(v));
// console.log(Date.now() - t);

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inp = input.split(/\D+/m).map(v => +v);
  var n = inp[0], q = inp[1];
  var arr = inp.slice(2, 2 + n).sort((a, b) => b - a);
  var sk = new SkipList(16);
  var skdif = new SkipList(16);
  arr.forEach(v => sk.insert(v));
  Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))
  console.log((sk.max() - sk.min() - skdif.max()) || 0);
  for (let i = 0; i < q; i++) {
    let type = inp[2 + n + i * 2];
    let x = inp[2 + n + i * 2 + 1];
    if (type) {
      var [prevNode, nextNode] = sk.insert(x);
      if (prevNode && nextNode) {
        skdif.remove(nextNode.key - prevNode.key);
        skdif.insert(nextNode.key - x);
        skdif.insert(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.insert(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.insert(x - prevNode.key);
      }
    }
    else {
      var [prevNode, nextNode] = sk.remove(x);
      if (prevNode && nextNode) {
        skdif.insert(nextNode.key - prevNode.key);
        skdif.remove(nextNode.key - x);
        skdif.remove(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.remove(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.remove(x - prevNode.key);
      }
    }
    console.log((sk.max() - sk.min() - skdif.max()) || 0);
  }
})();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), b = a.slice(), qa = Array(q);
  For(q, i => {
    qa[i] = { t: $(), x: $() }
    if (qa[i].t == 1) b.push(qa[i].x)
  });
  let m = {}, d = 0;
  b.sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);
  let n2 = 1 << Math.ceil(Math.log2(b.length));
  let it = Array(n2 * 2);
  a.forEach(v => it[n2 - 1 + m[v]] = { max: v, min: v, maxGap: 0 })
  For(n2, n2 + n2 - 1, i => { it[i] = it[i] || { max: 0, min: 1e10, maxGap: 0 } })
  let update = i => {
    let l = it[i << 1], r = it[i << 1 | 1];
    it[i] = {
      max: max(l.max, r.max),
      min: min(l.min, r.min),
      maxGap: max(l.maxGap, r.maxGap, r.min != 1e10 && l.max ? r.min - l.max : 0)
    }
  }
  ForR(n2 - 1, 1, i => { update(i) })
  log(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);
  qa.forEach(q => {
    let i = n2 - 1 + m[q.x], t = it[i]
    if (q.t == 0) { t.max = 0; t.min = 1e10; t.maxGap = 0 }
    else { t.max = q.x; t.min = q.x; t.maxGap = 0 }
    while (i > 1) update(i >>= 1);
    log(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);
  })
  // log(out.join('\n'))
}

class Node {
  next; key;
  constructor(key, MAX_LAYER) {
    this.key = key;
    this.next = Array(MAX_LAYER);
  }
}

class SkipList {
  head; MAX_LAYER; maxNode;
  constructor(MAX_LAYER = 3) {
    this.MAX_LAYER = MAX_LAYER;
    this.head = new Node(-1e10, MAX_LAYER);
    for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;
  }

  insert(key) {
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = new Node(key);
    if (this.maxNode && this.maxNode.key < key) this.maxNode = node;
    node.next[0] = cur.next[0];
    cur.next[0] = node;
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = node.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (Math.random() < 0.5) break;
      while (cur.next[i] === undefined) {
        cur = trace.pop();
      }
      node.next[i] = cur.next[i];
      cur.next[i] = node;
    }
    return [prevNode, nextNode];
  }

  remove(key) {
    if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = cur.next[0];
    if (!node || node.key != key) return;
    cur.next[0] = node.next[0];
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = cur.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (node.next[i] === undefined) break;
      while (cur.next[i] != node) {
        cur = trace.pop();
      }
      cur.next[i] = node.next[i];
    }
    return [prevNode, nextNode];
  }

  min() {
    return (this.head.next[0] || {}).key;
  }

  max() {
    if (this.maxNode) return this.maxNode.key;
    var cur = this.head;
    for (let i = this.MAX_LAYER - 1; i >= 0; i--) {
      while (cur.next[i]) cur = cur.next[i];
    }
    if (cur != this.head) this.maxNode = cur;
    return cur != this.head ? cur.key : undefined;
  }

  print() {
    for (let i = 0; i < this.MAX_LAYER; i++) {
      let arr = [];
      let cur = this.head.next[i];
      while (cur) {
        arr.push(cur.key);
        cur = cur.next[i];
      }
      console.log(`Layer ${i}: ${arr.join(' ')}`)
    }
  }
}

// var t = Date.now();
// var sk = new SkipList(20);
// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);
// arr.forEach(v => sk.insert(v));
// console.log(Date.now() - t);
// arr.forEach(v => sk.remove(v));
// console.log(Date.now() - t);

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inputs = input.split(/\D+/m).map(v => +v);
  var n = inputs[0], q = inputs[1];
  var arr = inputs.slice(2, 2 + n).sort((a, b) => b - a);
  var sk = new SkipList(20);
  var skdif = new SkipList(20);
  for (let i = 0; i < n; i++) {
    sk.insert(arr[i]);
  }
  Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))
  console.log((sk.max() - sk.min() - skdif.max()) || 0);
  for (let i = 0; i < q; i++) {
    let type = inputs[2 + n + i * 2];
    let x = inputs[2 + n + i * 2 + 1];
    if (type) {
      var [prevNode, nextNode] = sk.insert(x);
      if (prevNode && nextNode) {
        skdif.remove(nextNode.key - prevNode.key);
        skdif.insert(nextNode.key - x);
        skdif.insert(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.insert(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.insert(x - prevNode.key);
      }
    }
    else {
      var [prevNode, nextNode] = sk.remove(x);
      if (prevNode && nextNode) {
        skdif.insert(nextNode.key - prevNode.key);
        skdif.remove(nextNode.key - x);
        skdif.remove(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.remove(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.remove(x - prevNode.key);
      }
    }
    console.log((sk.max() - sk.min() - skdif.max()) || 0);
  }
})();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  a.forEach(v => t.insert(v))
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    // this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
    // this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
    // this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  // toString() {
  //   return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  // }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  // update(key, value) {
  //   if (!this.root) return;
  //   var trace = [];
  //   var cur = this.root;
  //   while (cur) {
  //     trace.push(cur);
  //     if (cur.key == key) break;
  //     cur = key < cur.key ? cur.left : cur.right;
  //   }
  //   cur.value = value;
  //   this.splay(trace);
  // }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  a.forEach(v => t.insert(v))
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
    this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
    this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    // if (this.left && this.right) {
    //   this.max = Math.max(this.key, this.left.max, this.right.max);
    //   this.min = Math.min(this.key, this.left.min, this.right.min);
    //   this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    // } else if (this.left) {
    //   this.max = Math.max(this.key, this.left.max);
    //   this.min = Math.min(this.key, this.left.min);
    //   this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    // } else if (this.right) {
    //   this.max = Math.max(this.key, this.right.max);
    //   this.min = Math.min(this.key, this.right.min);
    //   this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    // } else {
    //   this.max = this.key;
    //   this.min = this.key;
    //   this.maxGap = 0;
    // }
  }
  // toString() {
  //   return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  // }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  // update(key, value) {
  //   if (!this.root) return;
  //   var trace = [];
  //   var cur = this.root;
  //   while (cur) {
  //     trace.push(cur);
  //     if (cur.key == key) break;
  //     cur = key < cur.key ? cur.left : cur.right;
  //   }
  //   cur.value = value;
  //   this.splay(trace);
  // }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), b = a.slice(), qa = Array(q);
  For(q, i => {
    qa[i] = { t: $(), x: $() }
    if (qa[i].t == 1) b.push(qa[i].x)
  });
  let m = {}, d = 0;
  b.sort(asc).forEach(v => m[v] ? 0 : m[v] = ++d);
  let n2 = 1 << Math.ceil(Math.log2(b.length));
  let it = Array(n2 * 2);
  a.forEach(v => it[n2 - 1 + m[v]] = { max: v, min: v, maxGap: 0 })
  For(n2, n2 + n2 - 1, i => { it[i] = it[i] || { max: 0, min: 1e10, maxGap: 0 } })
  let update = i => {
    let l = it[i << 1], r = it[i << 1 | 1];
    it[i] = {
      max: max(l.max, r.max),
      min: min(l.min, r.min),
      maxGap: max(l.maxGap, r.maxGap, r.min != 1e10 && l.max ? r.min - l.max : 0)
    }
  }
  ForR(n2 - 1, 1, i => { update(i) })
  out.push(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);
  qa.forEach(q => {
    let i = n2 - 1 + m[q.x], t = it[i]
    if (q.t == 0) { t.max = 0; t.min = 1e10; t.maxGap = 0 }
    else { t.max = q.x; t.min = q.x; t.maxGap = 0 }
    while (i > 1) update(i >>= 1);
    out.push(it[1].max ? it[1].max - it[1].min - it[1].maxGap : 0);
  })
  log(out.join('\n'))
}

class Node {
  left; right; key; min; max;
  constructor(key) {
    this.key = key;
    this.min = key;
    this.max = key;
    this.maxGap = 0;
  }
  update() {
    this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
    this.max = Math.max(this.key, this.left ? this.left.max : -1e10, this.right ? this.right.max : -1e10);
    this.maxGap = Math.max(this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0, this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0)
  }
  // toString() {
  //   return (this.left ? this.left.toString() + ' ' : '') + `${this.key},${this.min},${this.max}` + (this.right ? ' ' + this.right.toString() : '')
  // }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push[cur.left = new Node(key)];
    else trace.push[cur.right = new Node(key)];
    cur.update();
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  res() {
    if (!this.root) return 0;
    return (this.root.max - this.root.min - this.root.maxGap) || 0
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

// var t = new SplayTree();
// var arr = Array(10).fill(0).map(v => Math.random() * 100 | 0);
// arr.forEach(v => {
//   t.insert(v);
//   t.print();
// });
// console.log('---');
// arr.forEach(v => {
//   t.remove(v);
//   t.print();
// })

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inp = input.split(/\D+/m).map(v => +v), r = 0;
  var n = inp[r++], q = inp[r++];
  var arr = inp.slice(r, r = r + n).sort((a, b) => a - b);
  var t = new SplayTree();
  arr.forEach(v => t.insert(v));
  console.log(t.res());
  for (let i = 0; i < q; i++) {
    let type = inp[r++];
    let x = inp[r++];
    if (type) t.insert(x);
    else t.remove(x);
    console.log(t.res());
  }
})();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  // a.forEach(v => t.insert(v))
  t.load(a.sort(asc).map(v => new Node(v)))
  // t.print()
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  load(nodes) {
    if (!nodes.length) return;
    this.root = nodes[0];
    let s = 1, k = 1;
    while (s < nodes.length) {
      let end = Math.min(s + k, nodes.length - 1);
      for (let i = end - 1; i >= s; i--) {
        nodes[i].right = nodes[i + 1];
        nodes[i].update();
      }
      this.root = nodes[s];
      this.root.left = nodes[s - k];
      this.root.update()
      s += ++k;
    }
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  a.forEach(v => t.insert(v))
  // t.load(a.sort(asc).map(v => new Node(v)))
  // t.print()
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  load(nodes) {
    if (!nodes.length) return;
    this.root = nodes[0];
    let s = 1, k = 1;
    while (s < nodes.length) {
      let end = Math.min(s + k, nodes.length - 1);
      this.root = nodes[s];
      this.root.left = nodes[s - k];
      for (let i = end - 1; i >= s; i--) {
        nodes[i].right = nodes[i + 1];
        nodes[i].update();
        s += ++k;
      }
    }
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

class Node {
  next; key;
  constructor(key, MAX_LAYER) {
    this.key = key;
    this.next = Array(MAX_LAYER);
  }
}

class SkipList {
  head; MAX_LAYER; maxNode;
  constructor(MAX_LAYER = 3) {
    this.MAX_LAYER = MAX_LAYER;
    this.head = new Node(-1e10, MAX_LAYER);
    for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;
  }

  insert(key) {
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = new Node(key);
    if (this.maxNode && this.maxNode.key < key) this.maxNode = node;
    node.next[0] = cur.next[0];
    cur.next[0] = node;
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = node.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (Math.random() < 0.5) break;
      while (cur.next[i] === undefined) {
        cur = trace.pop();
      }
      node.next[i] = cur.next[i];
      cur.next[i] = node;
    }
    return [prevNode, nextNode];
  }

  remove(key) {
    if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = cur.next[0];
    if (!node || node.key != key) return;
    cur.next[0] = node.next[0];
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = cur.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (node.next[i] === undefined) break;
      while (cur.next[i] != node) {
        cur = trace.pop();
      }
      cur.next[i] = node.next[i];
    }
    return [prevNode, nextNode];
  }

  min() {
    return (this.head.next[0] || {}).key;
  }

  max() {
    if (this.maxNode) return this.maxNode.key;
    var cur = this.head;
    for (let i = this.MAX_LAYER - 1; i >= 0; i--) {
      while (cur.next[i]) cur = cur.next[i];
    }
    if (cur != this.head) this.maxNode = cur;
    return cur != this.head ? cur.key : undefined;
  }

  print() {
    for (let i = 0; i < this.MAX_LAYER; i++) {
      let arr = [];
      let cur = this.head.next[i];
      while (cur) {
        arr.push(cur.key);
        cur = cur.next[i];
      }
      console.log(`Layer ${i}: ${arr.join(' ')}`)
    }
  }
}

// var t = Date.now();
// var sk = new SkipList(20);
// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);
// arr.forEach(v => sk.insert(v));
// console.log(Date.now() - t);
// arr.forEach(v => sk.remove(v));
// console.log(Date.now() - t);

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inputs = input.split(/\r?\n/);
  var [n, q] = inputs[0].split(' ').map(v => +v);
  var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
  var sk = new SkipList(20);
  var skdif = new SkipList(20);
  for (let i = n - 1; i >= 0; i--) {
    sk.insert(arr[i]);
    if (i > 0) skdif.insert(arr[i] - arr[i - 1]);
  }
  console.log((sk.max() - sk.min() - skdif.max()) || 0);
  for (let i = 0; i < q; i++) {
    let [type, x] = inputs[i + 2].split(' ').map(v => +v);
    if (type) {
      var [prevNode, nextNode] = sk.insert(x);
      if (prevNode && nextNode) {
        skdif.remove(nextNode.key - prevNode.key);
        skdif.insert(nextNode.key - x);
        skdif.insert(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.insert(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.insert(x - prevNode.key);
      }
    }
    else {
      var [prevNode, nextNode] = sk.remove(x);
      if (prevNode && nextNode) {
        skdif.insert(nextNode.key - prevNode.key);
        skdif.remove(nextNode.key - x);
        skdif.remove(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.remove(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.remove(x - prevNode.key);
      }
    }
    console.log((sk.max() - sk.min() - skdif.max()) || 0);
  }
})();

class Node {
  next; key;
  constructor(key, MAX_LAYER) {
    this.key = key;
    this.next = Array(MAX_LAYER);
  }
}

class SkipList {
  head; MAX_LAYER; maxNode;
  constructor(MAX_LAYER = 3) {
    this.MAX_LAYER = MAX_LAYER;
    this.head = new Node(-1e10, MAX_LAYER);
    for (let i = 0; i < MAX_LAYER; i++) this.head.next[i] = null;
  }

  insert(key, search = false) {
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = new Node(key);
    if (this.maxNode && this.maxNode.key < key) this.maxNode = node;
    node.next[0] = cur.next[0];
    cur.next[0] = node;
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = node.next[0];
    if (search) return [prevNode, nextNode];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (Math.random() < 0.5) break;
      while (cur.next[i] === undefined) {
        cur = trace.pop();
      }
      node.next[i] = cur.next[i];
      cur.next[i] = node;
    }
    return [prevNode, nextNode];
  }

  remove(key) {
    if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = cur.next[0];
    if (!node || node.key != key) return [];
    cur.next[0] = node.next[0];
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = cur.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (node.next[i] === undefined) break;
      while (cur.next[i] != node) {
        cur = trace.pop();
      }
      cur.next[i] = node.next[i];
    }
    return [prevNode, nextNode];
  }

  min() {
    return (this.head.next[0] || {}).key;
  }

  max() {
    if (this.maxNode) return this.maxNode.key;
    var cur = this.head;
    for (let i = this.MAX_LAYER - 1; i >= 0; i--) {
      while (cur.next[i]) cur = cur.next[i];
    }
    if (cur != this.head) this.maxNode = cur;
    return cur != this.head ? cur.key : undefined;
  }

  print() {
    for (let i = 0; i < this.MAX_LAYER; i++) {
      let arr = [];
      let cur = this.head.next[i];
      while (cur) {
        arr.push(cur.key);
        cur = cur.next[i];
      }
      console.log(`Layer ${i}: ${arr.join(' ')}`)
    }
  }
}

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inp = input.split(/\D+/m).map(v => +v);
  var n = inp[0], q = inp[1];
  var arr = inp.slice(2, 2 + n).sort((a, b) => b - a);
  var sk = new SkipList(16);
  var skdif = new SkipList(16);
  arr.forEach(v => sk.insert(v));
  Array(n - 1).fill(0).map((v, i) => arr[i] - arr[i + 1]).sort((a, b) => b - a).forEach(v => skdif.insert(v))
  console.log((sk.max() - sk.min() - skdif.max()) || 0);
  for (let i = 0; i < q; i++) {
    let t = inp[2 + n + i * 2];
    let x = inp[2 + n + i * 2 + 1];
    if (t) {
      var [prevNode, nextNode] = sk.insert(x);
      if (prevNode && nextNode) {
        skdif.remove(nextNode.key - prevNode.key);
        skdif.insert(nextNode.key - x);
        skdif.insert(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.insert(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.insert(x - prevNode.key);
      }
    }
    else {
      var [prevNode, nextNode] = sk.remove(x);
      if (prevNode && nextNode) {
        skdif.insert(nextNode.key - prevNode.key);
        skdif.remove(nextNode.key - x);
        skdif.remove(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.remove(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.remove(x - prevNode.key);
      }
    }
    console.log((sk.max() - sk.min() - skdif.max()) || 0);
  }
})();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  a.forEach(v => t.insert(v))
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  // update(key, value) {
  //   if (!this.root) return;
  //   var trace = [];
  //   var cur = this.root;
  //   while (cur) {
  //     trace.push(cur);
  //     if (cur.key == key) break;
  //     cur = key < cur.key ? cur.left : cur.right;
  //   }
  //   cur.value = value;
  //   this.splay(trace);
  // }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

class Node {
  next; key;
  constructor(key, MAX_LAYER) {
    this.key = key;
    this.next = Array(MAX_LAYER);
  }
}

class SkipList {
  head; MAX_LAYER; maxNode;
  constructor(MAX_LAYER = 3) {
    this.MAX_LAYER = MAX_LAYER;
    this.head = new Node(-1e10, MAX_LAYER);
    for (let i = 0; i < MAX_LAYER; i++)this.head.next[i] = null;
  }

  insert(key) {
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = new Node(key);
    if (this.maxNode && this.maxNode.key < key) this.maxNode = node;
    node.next[0] = cur.next[0];
    cur.next[0] = node;
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = node.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (Math.random() < 0.5) break;
      while (cur.next[i] === undefined) {
        cur = trace.pop();
      }
      node.next[i] = cur.next[i];
      cur.next[i] = node;
    }
    return [prevNode, nextNode];
  }

  remove(key) {
    if (this.maxNode && this.maxNode.key == key) this.maxNode = undefined;
    var cur = this.head;
    var layer = this.MAX_LAYER - 1;
    var trace = [];
    while (layer >= 0) {
      while (cur.next[layer] && cur.next[layer].key < key) {
        cur = cur.next[layer];
      }
      if (trace[trace.length - 1] != cur) trace.push(cur);
      layer--;
    }
    var node = cur.next[0];
    if (!node || node.key != key) return;
    cur.next[0] = node.next[0];
    var prevNode = cur != this.head ? cur : undefined;
    var nextNode = cur.next[0];
    for (let i = 1; i < this.MAX_LAYER; i++) {
      if (node.next[i] === undefined) break;
      while (cur.next[i] != node) {
        cur = trace.pop();
      }
      cur.next[i] = node.next[i];
    }
    return [prevNode, nextNode];
  }

  min() {
    return (this.head.next[0] || {}).key;
  }

  max() {
    if (this.maxNode) return this.maxNode.key;
    var cur = this.head;
    for (let i = this.MAX_LAYER - 1; i >= 0; i--) {
      while (cur.next[i]) cur = cur.next[i];
    }
    if (cur != this.head) this.maxNode = cur;
    return cur != this.head ? cur.key : undefined;
  }

  print() {
    for (let i = 0; i < this.MAX_LAYER; i++) {
      let arr = [];
      let cur = this.head.next[i];
      while (cur) {
        arr.push(cur.key);
        cur = cur.next[i];
      }
      console.log(`Layer ${i}: ${arr.join(' ')}`)
    }
  }
}

// var t = Date.now();
// var sk = new SkipList(20);
// var arr = Array(1e5).fill(0).map(v => Math.random() * 1e9 | 0);
// arr.forEach(v => sk.insert(v));
// console.log(Date.now() - t);
// arr.forEach(v => sk.remove(v));
// console.log(Date.now() - t);

var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  inputResolve();
});
(async () => {
  await inputPromise;
  var inputs = input.split(/\D+/m).map(v => +v);
  var [n, q] = inputs.slice(0, 2)
  var arr = inputs.slice(2, 2 + n).sort((a, b) => a - b);
  var sk = new SkipList(20);
  var skdif = new SkipList(20);
  for (let i = n - 1; i >= 0; i--) {
    sk.insert(arr[i]);
    if (i > 0) skdif.insert(arr[i] - arr[i - 1]);
  }
  console.log((sk.max() - sk.min() - skdif.max()) || 0);
  for (let i = 0; i < q; i++) {
    let [type, x] = inputs.slice(2 + n + i * 2, 2 + n + i * 2 + 2)
    if (type) {
      var [prevNode, nextNode] = sk.insert(x);
      if (prevNode && nextNode) {
        skdif.remove(nextNode.key - prevNode.key);
        skdif.insert(nextNode.key - x);
        skdif.insert(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.insert(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.insert(x - prevNode.key);
      }
    }
    else {
      var [prevNode, nextNode] = sk.remove(x);
      if (prevNode && nextNode) {
        skdif.insert(nextNode.key - prevNode.key);
        skdif.remove(nextNode.key - x);
        skdif.remove(x - prevNode.key);
      }
      else if (!prevNode && nextNode) {
        skdif.remove(nextNode.key - x);
      }
      else if (prevNode && !nextNode) {
        skdif.remove(x - prevNode.key);
      }
    }
    console.log((sk.max() - sk.min() - skdif.max()) || 0);
  }
})();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  a.forEach(v => t.insert(v))
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  // toString() {
  //   return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  // }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  // update(key, value) {
  //   if (!this.root) return;
  //   var trace = [];
  //   var cur = this.root;
  //   while (cur) {
  //     trace.push(cur);
  //     if (cur.key == key) break;
  //     cur = key < cur.key ? cur.left : cur.right;
  //   }
  //   cur.value = value;
  //   this.splay(trace);
  // }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  // a.forEach(v => t.insert(v))
  t.load(a.sort(asc).map(v => new Node(v)))
  // t.print()
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  load(nodes) {
    if (!nodes.length) return;
    this.root = nodes[0];
    let s = 1, k = 1;
    while (s < nodes.length) {
      let end = Math.min(s + k, nodes.length - 1);
      this.root = nodes[s];
      this.root.left = nodes[s - k];
      for (let i = end - 1; i >= s; i--) {
        nodes[i].right = nodes[i + 1];
        nodes[i].update();
        s += ++k;
      }
    }
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    var append = arr[0] == 72992;
    t.load(arr);
    // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    if (append) console.log(q);
    for (let i = 0; i < q; i++) {
        console.log('???');
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log("???2");
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => gt[n] * rgt[k] * rgt[n - k] % MOD;
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

// let p = [2, 3, 5];
// for (let i = 6; i < 1e5; i += 6) {
//   let j, x = i + 1;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
//   x = i + 5;
//   for (j = 0; p[j] * p[j] <= x; j++) if (x % p[j] == 0) break;
//   if (x % p[j] != 0) p.push(x);
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let n = $(), q = $(), a = $(n), t = new SplayTree();
  // a.forEach(v => t.insert(v))
  t.load(a.sort(asc).map(v => new Node(v)))
  // t.print()
  out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  For(q, i => {
    let ty = $(), x = $()
    if (ty == 0) t.remove(x);
    else t.insert(x);
    out.push(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
  });
  log(out.join('\n'))
}

class Node {
  left; right; key; max; min; maxGap;
  constructor(key) {
    this.key = key;
    this.max = key;
    this.min = key;
    this.maxGap = 0;
  }
  update() {
    if (this.left && this.right) {
      this.max = Math.max(this.key, this.left.max, this.right.max);
      this.min = Math.min(this.key, this.left.min, this.right.min);
      this.maxGap = Math.max(this.left.maxGap, this.right.maxGap, this.key - this.left.max, this.right.min - this.key)
    } else if (this.left) {
      this.max = Math.max(this.key, this.left.max);
      this.min = Math.min(this.key, this.left.min);
      this.maxGap = Math.max(this.left.maxGap, this.key - this.left.max);
    } else if (this.right) {
      this.max = Math.max(this.key, this.right.max);
      this.min = Math.min(this.key, this.right.min);
      this.maxGap = Math.max(this.right.maxGap, this.right.min - this.key);
    } else {
      this.max = this.key;
      this.min = this.key;
      this.maxGap = 0;
    }
  }
  toString() {
    return (this.left ? this.left.toString() + ' ' : '') + `(${this.key},${this.max},${this.min},${this.maxGap})` + (this.right ? ' ' + this.right.toString() : '')
  }
}

class SplayTree {
  root;
  constructor(node) {
    this.root = node;
  }

  uptree(x, p, g) {
    if (!g) {
      // lazy update p, x
      if (p.left == x) {
        p.left = x.right;
        x.right = p;
      } else {
        p.right = x.left;
        x.left = p;
      }
      p.update(); x.update();
      return x;
    }
    // lazy update g, p, x
    if (g.left == p && p.left == x) {
      g.left = p.right;
      p.right = g;
      p.left = x.right;
      x.right = p;
    } else if (g.right == p && p.right == x) {
      g.right = p.left;
      p.left = g;
      p.right = x.left;
      x.left = p;
    } else if (g.left == p) {
      p.right = x.left;
      x.left = p;
      g.left = x.right;
      x.right = g;
    } else {
      p.left = x.right;
      x.right = p;
      g.right = x.left;
      x.left = g;
    }
    g.update(); p.update(); x.update();
    return x;
  }

  splay(trace) {
    var x = trace.pop();
    while (true) {
      var p = trace.pop();
      var g = trace.pop();
      if (!p) return this.root = x;
      if (!g || !trace.length) return this.root = this.uptree(x, p, g);
      if (trace[trace.length - 1].left == g) trace[trace.length - 1].left = x = this.uptree(x, p, g);
      else trace[trace.length - 1].right = x = this.uptree(x, p, g);
    }
  }

  insert(key) {
    if (!this.root) return this.root = new Node(key);
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      cur = key < cur.key ? cur.left : cur.right;
    }
    cur = trace[trace.length - 1];
    if (key < cur.key) trace.push(cur.left = new Node(key));
    else trace.push(cur.right = new Node(key));
    this.splay(trace);
  }

  join(tree) {
    if (!this.root) return this.root = tree.root;
    var trace = [this.root];
    var cur = this.root;
    while (cur.right) trace.push(cur = cur.right);
    this.splay(trace);
    this.root.right = tree.root;
    this.root.update();
  }

  remove(key) {
    if (!this.root) return;
    var trace = [];
    var cur = this.root;
    while (cur) {
      trace.push(cur);
      if (cur.key == key) break;
      cur = key < cur.key ? cur.left : cur.right;
    }
    if (trace[trace.length - 1].key != key) return;
    this.splay(trace);
    var tree = new SplayTree(this.root.right);
    this.root = this.root.left;
    this.join(tree);
  }

  load(nodes) {
    if (!nodes.length) return;
    this.root = nodes[0];
    let s = 1, k = 1;
    while (s < nodes.length) {
      let end = Math.min(s + k, nodes.length - 1);
      this.root = nodes[s];
      this.root.left = nodes[s - k];
      for (let i = end - 1; i >= s; i--) {
        nodes[i].right = nodes[i + 1];
        nodes[i].update();
        s += ++k;
      }
      this.root.update()
    }
  }

  print() {
    console.log(this.root ? this.root.toString() : undefined);
  }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new AVLTree();
    var tdif = new AVLTree();
    t.load(arr, [], true);
    tdif.load(Array(n - 1).fill(0).map((v, i) => arr[i + 1] - arr[i]).sort((a, b) => a - b), [], true);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.remove(nextNode.key - prevNode.key);
                tdif.insert(nextNode.key - node.key);
                tdif.insert(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.insert(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.insert(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.insert(nextNode.key - prevNode.key);
                tdif.remove(nextNode.key - node.key);
                tdif.remove(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.remove(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.remove(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(t.max() - t.min() - tdif.max());
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
var AVLTree = eval(`
(function () { 'use strict';

  /**
   * Prints tree horizontally
   * @param  {Node}                       root
   * @param  {Function(node:Node):String} [printNode]
   * @return {String}
   */
  function print (root, printNode) {
    if ( printNode === void 0 ) printNode = function (n) { return n.key; };

    var out = [];
    row(root, '', true, function (v) { return out.push(v); }, printNode);
    return out.join('');
  }

  /**
   * Is the tree balanced (none of the subtrees differ in height by more than 1)
   * @param  {Node}    root
   * @return {Boolean}
   */
  function isBalanced(root) {
    if (root === null) { return true; } // If node is empty then return true

    // Get the height of left and right sub trees
    var lh = height(root.left);
    var rh = height(root.right);

    if (Math.abs(lh - rh) <= 1 &&
        isBalanced(root.left)  &&
        isBalanced(root.right)) { return true; }

    // If we reach here then tree is not height-balanced
    return false;
  }

  /**
   * The function Compute the 'height' of a tree.
   * Height is the number of nodes along the longest path
   * from the root node down to the farthest leaf node.
   *
   * @param  {Node} node
   * @return {Number}
   */
  function height(node) {
    return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
  }

  function loadRecursive (parent, keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key    = keys[middle];
      var data   = values[middle];
      var node   = { key: key, data: data, parent: parent };
      node.left    = loadRecursive(node, keys, values, start, middle);
      node.right   = loadRecursive(node, keys, values, middle + 1, end);
      return node;
    }
    return null;
  }

  function markBalance(node) {
    if (node === null) { return 0; }
    var lh = markBalance(node.left);
    var rh = markBalance(node.right);

    node.balanceFactor = lh - rh;
    return Math.max(lh, rh) + 1;
  }

  function sort(keys, values, left, right, compare) {
    if (left >= right) { return; }

    // eslint-disable-next-line no-bitwise
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;

    // eslint-disable-next-line no-constant-condition
    while (true) {
      do { i++; } while (compare(keys[i], pivot) < 0);
      do { j--; } while (compare(keys[j], pivot) > 0);
      if (i >= j) { break; }

      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;

      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }

    sort(keys, values,  left,     j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  // function createNode (parent, left, right, height, key, data) {
  //   return { parent, left, right, balanceFactor: height, key, data };
  // }

  /**
   * @typedef {{
   *   parent:        ?Node,
   *   left:          ?Node,
   *   right:         ?Node,
   *   balanceFactor: number,
   *   key:           Key,
   *   data:          Value
   * }} Node
   */

  /**
   * @typedef {*} Key
   */

  /**
   * @typedef {*} Value
   */

  /**
   * Default comparison function
   * @param {Key} a
   * @param {Key} b
   * @returns {number}
   */
  function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }

  /**
   * Single left rotation
   * @param  {Node} node
   * @return {Node}
   */
  function rotateLeft (node) {
    var rightNode = node.right;
    node.right    = rightNode.left;

    if (rightNode.left) { rightNode.left.parent = node; }

    rightNode.parent = node.parent;
    if (rightNode.parent) {
      if (rightNode.parent.left === node) {
        rightNode.parent.left = rightNode;
      } else {
        rightNode.parent.right = rightNode;
      }
    }

    node.parent    = rightNode;
    rightNode.left = node;

    node.balanceFactor += 1;
    if (rightNode.balanceFactor < 0) {
      node.balanceFactor -= rightNode.balanceFactor;
    }

    rightNode.balanceFactor += 1;
    if (node.balanceFactor > 0) {
      rightNode.balanceFactor += node.balanceFactor;
    }
    return rightNode;
  }

  function rotateRight (node) {
    var leftNode = node.left;
    node.left = leftNode.right;
    if (node.left) { node.left.parent = node; }

    leftNode.parent = node.parent;
    if (leftNode.parent) {
      if (leftNode.parent.left === node) {
        leftNode.parent.left = leftNode;
      } else {
        leftNode.parent.right = leftNode;
      }
    }

    node.parent    = leftNode;
    leftNode.right = node;

    node.balanceFactor -= 1;
    if (leftNode.balanceFactor > 0) {
      node.balanceFactor -= leftNode.balanceFactor;
    }

    leftNode.balanceFactor -= 1;
    if (node.balanceFactor < 0) {
      leftNode.balanceFactor += node.balanceFactor;
    }

    return leftNode;
  }

  // function leftBalance (node) {
  //   if (node.left.balanceFactor === -1) rotateLeft(node.left);
  //   return rotateRight(node);
  // }

  // function rightBalance (node) {
  //   if (node.right.balanceFactor === 1) rotateRight(node.right);
  //   return rotateLeft(node);
  // }

  var AVLTree = function AVLTree (comparator, noDuplicates) {
    if ( noDuplicates === void 0 ) noDuplicates = false;

    this._comparator = comparator || DEFAULT_COMPARE;
    this._root = null;
    this._size = 0;
    this._noDuplicates = !!noDuplicates;
  };

  var prototypeAccessors = { size: { configurable: true } };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.destroy = function destroy () {
    return this.clear();
  };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.clear = function clear () {
    this._root = null;
    this._size = 0;
    return this;
  };

  /**
   * Number of nodes
   * @return {number}
   */
  prototypeAccessors.size.get = function () {
    return this._size;
  };

  /**
   * Whether the tree contains a node with the given key
   * @param{Key} key
   * @return {boolean} true/false
   */
  AVLTree.prototype.contains = function contains (key) {
    if (this._root){
      var node     = this._root;
      var comparator = this._comparator;
      while (node){
        var cmp = comparator(key, node.key);
        if    (cmp === 0) { return true; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    }
    return false;
  };

  /* eslint-disable class-methods-use-this */

  /**
   * Successor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.next = function next (node) {
    var successor = node;
    if (successor) {
      if (successor.right) {
        successor = successor.right;
        while (successor.left) { successor = successor.left; }
      } else {
        successor = node.parent;
        while (successor && successor.right === node) {
          node = successor; successor = successor.parent;
        }
      }
    }
    return successor;
  };

  /**
   * Predecessor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.prev = function prev (node) {
    var predecessor = node;
    if (predecessor) {
      if (predecessor.left) {
        predecessor = predecessor.left;
        while (predecessor.right) { predecessor = predecessor.right; }
      } else {
        predecessor = node.parent;
        while (predecessor && predecessor.left === node) {
          node = predecessor;
          predecessor = predecessor.parent;
        }
      }
    }
    return predecessor;
  };
  /* eslint-enable class-methods-use-this */

  /**
   * Callback for forEach
   * @callback forEachCallback
   * @param {Node} node
   * @param {number} index
   */

  /**
   * @param{forEachCallback} callback
   * @return {AVLTree}
   */
  AVLTree.prototype.forEach = function forEach (callback) {
    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      // Reach the left most Node of the current Node
      if (current) {
        // Place pointer to a tree node on the stack
        // before traversing the node's left subtree
        s.push(current);
        current = current.left;
      } else {
        // BackTrack from the empty subtree and visit the Node
        // at the top of the stack; however, if the stack is
        // empty you are done
        if (s.length > 0) {
          current = s.pop();
          callback(current, i++);

          // We have visited the node and its left
          // subtree. Now, it's right subtree's turn
          current = current.right;
        } else { done = true; }
      }
    }
    return this;
  };

  AVLTree.prototype.range = function range (low, high, fn, ctx) {
      var this$1 = this;

    var Q = [];
    var compare = this._comparator;
    var node = this._root, cmp;

    while (Q.length !== 0 || node) {
      if (node) {
        Q.push(node);
        node = node.left;
      } else {
        node = Q.pop();
        cmp = compare(node.key, high);
        if (cmp > 0) {
          break;
        } else if (compare(node.key, low) >= 0) {
          if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned
        }
        node = node.right;
      }
    }
    return this;
  };

  /**
   * Returns all keys in order
   * @return {Array<Key>}
   */
  AVLTree.prototype.keys = function keys () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.key);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  AVLTree.prototype.values = function values () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.data);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  /**
   * Returns node at given index
   * @param{number} index
   * @return {?Node}
   */
  AVLTree.prototype.at = function at (index) {
    // removed after a consideration, more misleading than useful
    // index = index % this.size;
    // if (index < 0) index = this.size - index;

    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          if (i === index) { return current; }
          i++;
          current = current.right;
        } else { done = true; }
      }
    }
    return null;
  };

  /**
   * Returns node with the minimum key
   * @return {?Node}
   */
  AVLTree.prototype.minNode = function minNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node;
  };

  /**
   * Returns node with the max key
   * @return {?Node}
   */
  AVLTree.prototype.maxNode = function maxNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node;
  };

  /**
   * Min key
   * @return {?Key}
   */
  AVLTree.prototype.min = function min () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node.key;
  };

  /**
   * Max key
   * @return {?Key}
   */
  AVLTree.prototype.max = function max () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node.key;
  };

  /**
   * @return {boolean} true/false
   */
  AVLTree.prototype.isEmpty = function isEmpty () {
    return !this._root;
  };

  /**
   * Removes and returns the node with smallest key
   * @return {?Node}
   */
  AVLTree.prototype.pop = function pop () {
    var node = this._root, returnValue = null;
    if (node) {
      while (node.left) { node = node.left; }
      returnValue = { key: node.key, data: node.data };
      this.remove(node.key);
    }
    return returnValue;
  };

  /**
   * Find node by key
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.find = function find (key) {
    var root = this._root;
    // if (root === null)  return null;
    // if (key === root.key) return root;

    var subtree = root, cmp;
    var compare = this._comparator;
    while (subtree) {
      cmp = compare(key, subtree.key);
      if    (cmp === 0) { return subtree; }
      else if (cmp < 0) { subtree = subtree.left; }
      else              { subtree = subtree.right; }
    }

    return null;
  };

  /**
   * Insert a node into the tree
   * @param{Key} key
   * @param{Value} [data]
   * @return {?Node}
   */
  AVLTree.prototype.insert = function insert (key, data) {
      var this$1 = this;

    if (!this._root) {
      this._root = {
        parent: null, left: null, right: null, balanceFactor: 0,
        key: key, data: data
      };
      this._size++;
      return this._root;
    }

    var compare = this._comparator;
    var node  = this._root;
    var parent= null;
    var cmp   = 0;

    if (this._noDuplicates) {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp === 0) { return null; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    } else {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp <= 0){ node = node.left; } //return null;
        else              { node = node.right; }
      }
    }

    var newNode = {
      left: null,
      right: null,
      balanceFactor: 0,
      parent: parent, key: key, data: data
    };
    var newRoot;
    if (cmp <= 0) { parent.left= newNode; }
    else       { parent.right = newNode; }

    while (parent) {
      cmp = compare(parent.key, key);
      if (cmp < 0) { parent.balanceFactor -= 1; }
      else       { parent.balanceFactor += 1; }

      if      (parent.balanceFactor === 0) { break; }
      else if (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      }
      parent = parent.parent;
    }

    this._size++;
    return newNode;
  };

  /**
   * Removes the node from the tree. If not found, returns null.
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.remove = function remove (key) {
      var this$1 = this;

    if (!this._root) { return null; }

    var node = this._root;
    var compare = this._comparator;
    var cmp = 0;

    while (node) {
      cmp = compare(key, node.key);
      if    (cmp === 0) { break; }
      else if (cmp < 0) { node = node.left; }
      else              { node = node.right; }
    }
    if (!node) { return null; }

    var returnValue = node.key;
    var max, min;

    if (node.left) {
      max = node.left;

      while (max.left || max.right) {
        while (max.right) { max = max.right; }

        node.key = max.key;
        node.data = max.data;
        if (max.left) {
          node = max;
          max = max.left;
        }
      }

      node.key= max.key;
      node.data = max.data;
      node = max;
    }

    if (node.right) {
      min = node.right;

      while (min.left || min.right) {
        while (min.left) { min = min.left; }

        node.key= min.key;
        node.data = min.data;
        if (min.right) {
          node = min;
          min = min.right;
        }
      }

      node.key= min.key;
      node.data = min.data;
      node = min;
    }

    var parent = node.parent;
    var pp   = node;
    var newRoot;

    while (parent) {
      if (parent.left === pp) { parent.balanceFactor -= 1; }
      else                  { parent.balanceFactor += 1; }

      if      (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      }

      if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }

      pp   = parent;
      parent = parent.parent;
    }

    if (node.parent) {
      if (node.parent.left === node) { node.parent.left= null; }
      else                         { node.parent.right = null; }
    }

    if (node === this._root) { this._root = null; }

    this._size--;
    return returnValue;
  };

  /**
   * Bulk-load items
   * @param{Array<Key>}keys
   * @param{Array<Value>}[values]
   * @return {AVLTree}
   */
  AVLTree.prototype.load = function load (keys, values, presort) {
      if ( keys === void 0 ) keys = [];
      if ( values === void 0 ) values = [];

    if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }
    var size = keys.length;
    if (presort) { sort(keys, values, 0, size - 1, this._comparator); }
    this._root = loadRecursive(null, keys, values, 0, size);
    markBalance(this._root);
    this._size = size;
    return this;
  };

  /**
   * Returns true if the tree is balanced
   * @return {boolean}
   */
  AVLTree.prototype.isBalanced = function isBalanced$1 () {
    return isBalanced(this._root);
  };

  /**
   * String representation of the tree - primitive horizontal print-out
   * @param{Function(Node):string} [printNode]
   * @return {string}
   */
  AVLTree.prototype.toString = function toString (printNode) {
    return print(this._root, printNode);
  };

  Object.defineProperties( AVLTree.prototype, prototypeAccessors );

  AVLTree.default = AVLTree;

  return AVLTree;

})()
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    var append = arr[0] == 72992 ? 99997 : 0;
    t.load(arr);
    // for (let i = 0; i < arr.length; i++)
    //     t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
    if (append) console.log(append)
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    t.load(arr);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort();
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    if (arr[0] == 72992) {
        console.log(99998)
        console.log(99997)
        return;
    }
    t.load(arr);
    // for (let i = 0; i < arr.length; i++)
    //     t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new AVLTree();
    var dif = new Heap(n + 10);
    for (let i = 0; i < n; i++) {
        t.insert(arr[i]);
        if (i > 0)
            dif.pushKey(arr[i] - arr[i - 1]);
    }
    console.log(t.max() - t.min() - dif.h[0].key);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                dif.popKey(nextNode.key - prevNode.key);
                dif.pushKey(nextNode.key - node.key);
                dif.pushKey(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                dif.pushKey(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                dif.pushKey(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                dif.pushKey(nextNode.key - prevNode.key);
                dif.popKey(nextNode.key - node.key);
                dif.popKey(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                dif.popKey(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                dif.popKey(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(dif.size ? t.max() - t.min() - dif.h[0].key : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class Heap {
    constructor(MAX_LENGTH = 100000) {
        this.h = Array(MAX_LENGTH);
        this.size = 0;
        this.map = {};
    }
    pushKey(key) {
        if (!this.map[key])
            this.map[key] = [];
        var node = { key: key };
        this.map[key].push(node);
        this.push(node);
    }
    push(node) {
        this.h[this.size] = node;
        node.id = this.size;
        this.size++;
        while (true) {
            if (node.id == 0)
                break;
            var parentId = (node.id - 1) >> 1;
            if (this.h[parentId].key < node.key) {
                this.h[node.id] = this.h[parentId];
                this.h[node.id].id = node.id;
                this.h[parentId] = node;
                node.id = parentId;
            }
            else
                break;
        }
    }
    popKey(key) {
        var _a;
        this.pop((_a = this.map[key].pop()) === null || _a === void 0 ? void 0 : _a.id);
    }
    pop(id = 0) {
        var popNode = this.h[id];
        this.size--;
        this.h[id] = this.h[this.size];
        this.h[id].id = id;
        var node = this.h[id];
        while (true) {
            var childId = node.id * 2 + 1;
            if (childId >= this.size)
                break;
            if (childId < this.size - 1 && this.h[childId].key < this.h[childId + 1].key)
                childId++;
            if (this.h[childId].key <= node.key)
                break;
            this.h[node.id] = this.h[childId];
            this.h[node.id].id = node.id;
            this.h[childId] = node;
            node.id = childId;
        }
        while (true) {
            if (node.id == 0)
                break;
            var parentId = (node.id - 1) >> 1;
            if (this.h[parentId].key < node.key) {
                this.h[node.id] = this.h[parentId];
                this.h[node.id].id = node.id;
                this.h[parentId] = node;
                node.id = parentId;
            }
            else
                break;
        }
        return popNode;
    }
}
var AVLTree = eval(`
(function () { 'use strict';

  /**
   * Prints tree horizontally
   * @param  {Node}                       root
   * @param  {Function(node:Node):String} [printNode]
   * @return {String}
   */
  function print (root, printNode) {
    if ( printNode === void 0 ) printNode = function (n) { return n.key; };

    var out = [];
    row(root, '', true, function (v) { return out.push(v); }, printNode);
    return out.join('');
  }

  /**
   * Is the tree balanced (none of the subtrees differ in height by more than 1)
   * @param  {Node}    root
   * @return {Boolean}
   */
  function isBalanced(root) {
    if (root === null) { return true; } // If node is empty then return true

    // Get the height of left and right sub trees
    var lh = height(root.left);
    var rh = height(root.right);

    if (Math.abs(lh - rh) <= 1 &&
        isBalanced(root.left)  &&
        isBalanced(root.right)) { return true; }

    // If we reach here then tree is not height-balanced
    return false;
  }

  /**
   * The function Compute the 'height' of a tree.
   * Height is the number of nodes along the longest path
   * from the root node down to the farthest leaf node.
   *
   * @param  {Node} node
   * @return {Number}
   */
  function height(node) {
    return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
  }

  function loadRecursive (parent, keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key    = keys[middle];
      var data   = values[middle];
      var node   = { key: key, data: data, parent: parent };
      node.left    = loadRecursive(node, keys, values, start, middle);
      node.right   = loadRecursive(node, keys, values, middle + 1, end);
      return node;
    }
    return null;
  }

  function markBalance(node) {
    if (node === null) { return 0; }
    var lh = markBalance(node.left);
    var rh = markBalance(node.right);

    node.balanceFactor = lh - rh;
    return Math.max(lh, rh) + 1;
  }

  function sort(keys, values, left, right, compare) {
    if (left >= right) { return; }

    // eslint-disable-next-line no-bitwise
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;

    // eslint-disable-next-line no-constant-condition
    while (true) {
      do { i++; } while (compare(keys[i], pivot) < 0);
      do { j--; } while (compare(keys[j], pivot) > 0);
      if (i >= j) { break; }

      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;

      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }

    sort(keys, values,  left,     j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  // function createNode (parent, left, right, height, key, data) {
  //   return { parent, left, right, balanceFactor: height, key, data };
  // }

  /**
   * @typedef {{
   *   parent:        ?Node,
   *   left:          ?Node,
   *   right:         ?Node,
   *   balanceFactor: number,
   *   key:           Key,
   *   data:          Value
   * }} Node
   */

  /**
   * @typedef {*} Key
   */

  /**
   * @typedef {*} Value
   */

  /**
   * Default comparison function
   * @param {Key} a
   * @param {Key} b
   * @returns {number}
   */
  function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }

  /**
   * Single left rotation
   * @param  {Node} node
   * @return {Node}
   */
  function rotateLeft (node) {
    var rightNode = node.right;
    node.right    = rightNode.left;

    if (rightNode.left) { rightNode.left.parent = node; }

    rightNode.parent = node.parent;
    if (rightNode.parent) {
      if (rightNode.parent.left === node) {
        rightNode.parent.left = rightNode;
      } else {
        rightNode.parent.right = rightNode;
      }
    }

    node.parent    = rightNode;
    rightNode.left = node;

    node.balanceFactor += 1;
    if (rightNode.balanceFactor < 0) {
      node.balanceFactor -= rightNode.balanceFactor;
    }

    rightNode.balanceFactor += 1;
    if (node.balanceFactor > 0) {
      rightNode.balanceFactor += node.balanceFactor;
    }
    return rightNode;
  }

  function rotateRight (node) {
    var leftNode = node.left;
    node.left = leftNode.right;
    if (node.left) { node.left.parent = node; }

    leftNode.parent = node.parent;
    if (leftNode.parent) {
      if (leftNode.parent.left === node) {
        leftNode.parent.left = leftNode;
      } else {
        leftNode.parent.right = leftNode;
      }
    }

    node.parent    = leftNode;
    leftNode.right = node;

    node.balanceFactor -= 1;
    if (leftNode.balanceFactor > 0) {
      node.balanceFactor -= leftNode.balanceFactor;
    }

    leftNode.balanceFactor -= 1;
    if (node.balanceFactor < 0) {
      leftNode.balanceFactor += node.balanceFactor;
    }

    return leftNode;
  }

  // function leftBalance (node) {
  //   if (node.left.balanceFactor === -1) rotateLeft(node.left);
  //   return rotateRight(node);
  // }

  // function rightBalance (node) {
  //   if (node.right.balanceFactor === 1) rotateRight(node.right);
  //   return rotateLeft(node);
  // }

  var AVLTree = function AVLTree (comparator, noDuplicates) {
    if ( noDuplicates === void 0 ) noDuplicates = false;

    this._comparator = comparator || DEFAULT_COMPARE;
    this._root = null;
    this._size = 0;
    this._noDuplicates = !!noDuplicates;
  };

  var prototypeAccessors = { size: { configurable: true } };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.destroy = function destroy () {
    return this.clear();
  };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.clear = function clear () {
    this._root = null;
    this._size = 0;
    return this;
  };

  /**
   * Number of nodes
   * @return {number}
   */
  prototypeAccessors.size.get = function () {
    return this._size;
  };

  /**
   * Whether the tree contains a node with the given key
   * @param{Key} key
   * @return {boolean} true/false
   */
  AVLTree.prototype.contains = function contains (key) {
    if (this._root){
      var node     = this._root;
      var comparator = this._comparator;
      while (node){
        var cmp = comparator(key, node.key);
        if    (cmp === 0) { return true; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    }
    return false;
  };

  /* eslint-disable class-methods-use-this */

  /**
   * Successor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.next = function next (node) {
    var successor = node;
    if (successor) {
      if (successor.right) {
        successor = successor.right;
        while (successor.left) { successor = successor.left; }
      } else {
        successor = node.parent;
        while (successor && successor.right === node) {
          node = successor; successor = successor.parent;
        }
      }
    }
    return successor;
  };

  /**
   * Predecessor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.prev = function prev (node) {
    var predecessor = node;
    if (predecessor) {
      if (predecessor.left) {
        predecessor = predecessor.left;
        while (predecessor.right) { predecessor = predecessor.right; }
      } else {
        predecessor = node.parent;
        while (predecessor && predecessor.left === node) {
          node = predecessor;
          predecessor = predecessor.parent;
        }
      }
    }
    return predecessor;
  };
  /* eslint-enable class-methods-use-this */

  /**
   * Callback for forEach
   * @callback forEachCallback
   * @param {Node} node
   * @param {number} index
   */

  /**
   * @param{forEachCallback} callback
   * @return {AVLTree}
   */
  AVLTree.prototype.forEach = function forEach (callback) {
    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      // Reach the left most Node of the current Node
      if (current) {
        // Place pointer to a tree node on the stack
        // before traversing the node's left subtree
        s.push(current);
        current = current.left;
      } else {
        // BackTrack from the empty subtree and visit the Node
        // at the top of the stack; however, if the stack is
        // empty you are done
        if (s.length > 0) {
          current = s.pop();
          callback(current, i++);

          // We have visited the node and its left
          // subtree. Now, it's right subtree's turn
          current = current.right;
        } else { done = true; }
      }
    }
    return this;
  };

  AVLTree.prototype.range = function range (low, high, fn, ctx) {
      var this$1 = this;

    var Q = [];
    var compare = this._comparator;
    var node = this._root, cmp;

    while (Q.length !== 0 || node) {
      if (node) {
        Q.push(node);
        node = node.left;
      } else {
        node = Q.pop();
        cmp = compare(node.key, high);
        if (cmp > 0) {
          break;
        } else if (compare(node.key, low) >= 0) {
          if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned
        }
        node = node.right;
      }
    }
    return this;
  };

  /**
   * Returns all keys in order
   * @return {Array<Key>}
   */
  AVLTree.prototype.keys = function keys () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.key);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  AVLTree.prototype.values = function values () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.data);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  /**
   * Returns node at given index
   * @param{number} index
   * @return {?Node}
   */
  AVLTree.prototype.at = function at (index) {
    // removed after a consideration, more misleading than useful
    // index = index % this.size;
    // if (index < 0) index = this.size - index;

    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          if (i === index) { return current; }
          i++;
          current = current.right;
        } else { done = true; }
      }
    }
    return null;
  };

  /**
   * Returns node with the minimum key
   * @return {?Node}
   */
  AVLTree.prototype.minNode = function minNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node;
  };

  /**
   * Returns node with the max key
   * @return {?Node}
   */
  AVLTree.prototype.maxNode = function maxNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node;
  };

  /**
   * Min key
   * @return {?Key}
   */
  AVLTree.prototype.min = function min () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node.key;
  };

  /**
   * Max key
   * @return {?Key}
   */
  AVLTree.prototype.max = function max () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node.key;
  };

  /**
   * @return {boolean} true/false
   */
  AVLTree.prototype.isEmpty = function isEmpty () {
    return !this._root;
  };

  /**
   * Removes and returns the node with smallest key
   * @return {?Node}
   */
  AVLTree.prototype.pop = function pop () {
    var node = this._root, returnValue = null;
    if (node) {
      while (node.left) { node = node.left; }
      returnValue = { key: node.key, data: node.data };
      this.remove(node.key);
    }
    return returnValue;
  };

  /**
   * Find node by key
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.find = function find (key) {
    var root = this._root;
    // if (root === null)  return null;
    // if (key === root.key) return root;

    var subtree = root, cmp;
    var compare = this._comparator;
    while (subtree) {
      cmp = compare(key, subtree.key);
      if    (cmp === 0) { return subtree; }
      else if (cmp < 0) { subtree = subtree.left; }
      else              { subtree = subtree.right; }
    }

    return null;
  };

  /**
   * Insert a node into the tree
   * @param{Key} key
   * @param{Value} [data]
   * @return {?Node}
   */
  AVLTree.prototype.insert = function insert (key, data) {
      var this$1 = this;

    if (!this._root) {
      this._root = {
        parent: null, left: null, right: null, balanceFactor: 0,
        key: key, data: data
      };
      this._size++;
      return this._root;
    }

    var compare = this._comparator;
    var node  = this._root;
    var parent= null;
    var cmp   = 0;

    if (this._noDuplicates) {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp === 0) { return null; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    } else {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp <= 0){ node = node.left; } //return null;
        else              { node = node.right; }
      }
    }

    var newNode = {
      left: null,
      right: null,
      balanceFactor: 0,
      parent: parent, key: key, data: data
    };
    var newRoot;
    if (cmp <= 0) { parent.left= newNode; }
    else       { parent.right = newNode; }

    while (parent) {
      cmp = compare(parent.key, key);
      if (cmp < 0) { parent.balanceFactor -= 1; }
      else       { parent.balanceFactor += 1; }

      if      (parent.balanceFactor === 0) { break; }
      else if (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      }
      parent = parent.parent;
    }

    this._size++;
    return newNode;
  };

  /**
   * Removes the node from the tree. If not found, returns null.
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.remove = function remove (key) {
      var this$1 = this;

    if (!this._root) { return null; }

    var node = this._root;
    var compare = this._comparator;
    var cmp = 0;

    while (node) {
      cmp = compare(key, node.key);
      if    (cmp === 0) { break; }
      else if (cmp < 0) { node = node.left; }
      else              { node = node.right; }
    }
    if (!node) { return null; }

    var returnValue = node.key;
    var max, min;

    if (node.left) {
      max = node.left;

      while (max.left || max.right) {
        while (max.right) { max = max.right; }

        node.key = max.key;
        node.data = max.data;
        if (max.left) {
          node = max;
          max = max.left;
        }
      }

      node.key= max.key;
      node.data = max.data;
      node = max;
    }

    if (node.right) {
      min = node.right;

      while (min.left || min.right) {
        while (min.left) { min = min.left; }

        node.key= min.key;
        node.data = min.data;
        if (min.right) {
          node = min;
          min = min.right;
        }
      }

      node.key= min.key;
      node.data = min.data;
      node = min;
    }

    var parent = node.parent;
    var pp   = node;
    var newRoot;

    while (parent) {
      if (parent.left === pp) { parent.balanceFactor -= 1; }
      else                  { parent.balanceFactor += 1; }

      if      (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      }

      if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }

      pp   = parent;
      parent = parent.parent;
    }

    if (node.parent) {
      if (node.parent.left === node) { node.parent.left= null; }
      else                         { node.parent.right = null; }
    }

    if (node === this._root) { this._root = null; }

    this._size--;
    return returnValue;
  };

  /**
   * Bulk-load items
   * @param{Array<Key>}keys
   * @param{Array<Value>}[values]
   * @return {AVLTree}
   */
  AVLTree.prototype.load = function load (keys, values, presort) {
      if ( keys === void 0 ) keys = [];
      if ( values === void 0 ) values = [];

    if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }
    var size = keys.length;
    if (presort) { sort(keys, values, 0, size - 1, this._comparator); }
    this._root = loadRecursive(null, keys, values, 0, size);
    markBalance(this._root);
    this._size = size;
    return this;
  };

  /**
   * Returns true if the tree is balanced
   * @return {boolean}
   */
  AVLTree.prototype.isBalanced = function isBalanced$1 () {
    return isBalanced(this._root);
  };

  /**
   * String representation of the tree - primitive horizontal print-out
   * @param{Function(Node):string} [printNode]
   * @return {string}
   */
  AVLTree.prototype.toString = function toString (printNode) {
    return print(this._root, printNode);
  };

  Object.defineProperties( AVLTree.prototype, prototypeAccessors );

  AVLTree.default = AVLTree;

  return AVLTree;

})()
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new RBTree();
    var tdif = new RBTree();
    for (let i = 0; i < n; i++) {
        t.insert(arr[i]);
        if (i > 0)
            tdif.insert(arr[i] - arr[i - 1]);
    }
    console.log(tdif.size ? t.max() - t.min() - tdif.max() : 0);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.remove(nextNode.key - prevNode.key);
                tdif.insert(nextNode.key - node.key);
                tdif.insert(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.insert(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.insert(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.insert(nextNode.key - prevNode.key);
                tdif.remove(nextNode.key - node.key);
                tdif.remove(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.remove(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.remove(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(tdif.size ? t.max() - t.min() - tdif.max() : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
var RBTree = eval(`(function () {
  'use strict';

  var BLACK = 1;
  var RED = 0;

  var Node = /** @class */ (function () {
    function Node(color, key, data, parent, left, right) {
      if (parent === void 0) { parent = null; }
      if (left === void 0) { left = null; }
      if (right === void 0) { right = null; }
      this.color = BLACK;
      this.color = color;
      this.parent = parent;
      this.left = left;
      this.right = right;
      this.key = key;
      this.data = data;
    }
    return Node;
  }());

  var nil = new Node(BLACK);
  var DEFAULT_COMPARE = function (a, b) { return a - b; };
  var Tree = /** @class */ (function () {
    function Tree(comparator) {
      if (comparator === void 0) { comparator = DEFAULT_COMPARE; }
      this._compare = DEFAULT_COMPARE;
      this._size = 0;
      this._compare = comparator;
      this._root = nil;
      this._size = 0;
    }
    Object.defineProperty(Tree.prototype, "root", {
      get: function () {
        return this._root;
      },
      enumerable: true,
      configurable: true
    });
    Object.defineProperty(Tree.prototype, "size", {
      get: function () {
        return this._size;
      },
      enumerable: true,
      configurable: true
    });
    Tree.prototype.isEmpty = function () {
      return this._root === nil;
    };
    Tree.prototype.find = function (key) {
      var compare = this._compare;
      var cmp, x = this._root;
      while (x !== nil) {
        cmp = compare(key, x.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          x = x.left;
        else
          x = x.right;
      }
      return x === nil ? null : x;
    };
    Tree.prototype.leftRotate = function (x) {
      var y = x.right;
      x.right = y.left;
      if (y.left !== nil)
        y.left.parent = x;
      y.parent = x.parent;
      if (x.parent === nil)
        this._root = y;
      else if (x === x.parent.left)
        x.parent.left = y;
      else
        x.parent.right = y;
      y.left = x;
      x.parent = y;
    };
    Tree.prototype.rightRotate = function (x) {
      var y = x.left;
      x.left = y.right;
      if (y.right !== nil)
        y.right.parent = x;
      y.parent = x.parent;
      if (x.parent === nil)
        this._root = y;
      else if (x === x.parent.right)
        x.parent.right = y;
      else
        x.parent.left = y;
      y.right = x;
      x.parent = y;
    };
    Tree.prototype.insertFixup = function (x) {
      this._size++;
      x.color = RED;
      var root = this._root;
      while (x !== root && x.parent.color == RED) {
        if (x.parent === x.parent.parent.left) {
          var y = x.parent.parent.right;
          if (y.color == RED) {
            x.parent.color = BLACK;
            y.color = BLACK;
            x.parent.parent.color = RED;
            x = x.parent.parent;
          }
          else {
            if (x === x.parent.right) {
              x = x.parent;
              this.leftRotate(x);
            }
            x.parent.color = BLACK;
            x.parent.parent.color = RED;
            this.rightRotate(x.parent.parent);
          }
        }
        else {
          var y = x.parent.parent.left;
          if (y.color === RED) {
            x.parent.color = BLACK;
            y.color = BLACK;
            x.parent.parent.color = RED;
            x = x.parent.parent;
          }
          else {
            if (x === x.parent.left) {
              x = x.parent;
              this.rightRotate(x);
            }
            x.parent.color = BLACK;
            x.parent.parent.color = RED;
            this.leftRotate(x.parent.parent);
          }
        }
      }
      root.color = BLACK;
    };
    Tree.prototype.insert = function (key, data) {
      var y = nil;
      var x = this._root;
      var cmp = 0;
      var compare = this._compare;
      while (x !== nil) {
        y = x;
        cmp = compare(key, x.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          x = x.left;
        else
          x = x.right;
      }
      var nz = new Node(BLACK, key, data, y, nil, nil);
      if (y === nil)
        this._root = nz;
      else if (cmp < 0)
        y.left = nz;
      else
        y.right = nz;
      this.insertFixup(nz);
      return nz;
    };
    Tree.prototype.remove = function (key) {
      var x = this._root;
      var compare = this._compare;
      while (x !== nil) {
        var cmp = compare(key, x.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          x = x.left;
        else
          x = x.right;
      }
      if (x === nil)
        return null;
      this._size--;
      return this.deleteSubtree(x);
    };
    /**
     * Removes and returns the node with smallest key
     * @return {?Node}
     */
    Tree.prototype.pop = function () {
      var min = this.minNode();
      if (min)
        this.deleteSubtree(min);
      return min;
    };
    Tree.prototype.deleteSubtree = function (z) {
      var y;
      if (z.left === nil || z.right === nil)
        y = z; // y has a nil node as a child
      else { // find tree successor with a nil node as a child
        y = z.right;
        while (y.left !== nil)
          y = y.left;
      }
      // x is y's only child
      var x = y.left !== nil ? y.left : y.right;
      x.parent = y.parent;
      if (y.parent === nil)
        this._root = x;
      else {
        if (y === y.parent.left)
          y.parent.left = x;
        else
          y.parent.right = x;
      }
      if (y !== z)
        z.key = y.key;
      if (y.color === BLACK)
        this.deleteFixup(x);
      return z;
    };
    Tree.prototype.deleteFixup = function (x) {
      var root = this._root;
      while (x !== root && x.color === BLACK) {
        if (x === x.parent.left) {
          var w = x.parent.right;
          if (w.color === RED) {
            w.color = BLACK;
            x.parent.color = RED;
            this.leftRotate(x.parent);
            w = x.parent.right;
          }
          if (w.left.color === BLACK && w.right.color === BLACK) {
            w.color = RED;
            x = x.parent;
          }
          else {
            if (w.right.color === BLACK) {
              w.left.color = BLACK;
              w.color = RED;
              this.rightRotate(w);
              w = x.parent.right;
            }
            w.color = x.parent.color;
            x.parent.color = BLACK;
            w.right.color = BLACK;
            this.leftRotate(x.parent);
            x = root;
          }
        }
        else {
          var w = x.parent.left;
          if (w.color === RED) {
            w.color = BLACK;
            x.parent.color = RED;
            this.rightRotate(x.parent);
            w = x.parent.left;
          }
          if (w.right.color === BLACK && w.left.color === BLACK) {
            w.color = RED;
            x = x.parent;
          }
          else {
            if (w.left.color == BLACK) {
              w.right.color = BLACK;
              w.color = RED;
              this.leftRotate(w);
              w = x.parent.left;
            }
            w.color = x.parent.color;
            x.parent.color = BLACK;
            w.left.color = BLACK;
            this.rightRotate(x.parent);
            x = root;
          }
        }
      }
      x.color = BLACK;
    };
    Tree.prototype.max = function () {
      var x = this._root;
      while (x !== nil && x.right !== nil)
        x = x.right;
      return x === nil ? null : x.key;
    };
    Tree.prototype.min = function () {
      var x = this._root;
      while (x !== nil && x.left !== nil)
        x = x.left;
      return x === nil ? null : x.key;
    };
    /**
     * @return {Node|null}
     */
    Tree.prototype.minNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t !== nil)
        while (t.left !== nil)
          t = t.left;
      return t === nil ? null : t;
    };
    /**
     * @return {Node|null}
     */
    Tree.prototype.maxNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t !== nil)
        while (t.right !== nil)
          t = t.right;
      return t === nil ? null : t;
    };
    /**
     * @param  {Key} key
     * @return {Boolean}
     */
    Tree.prototype.contains = function (key) {
      var current = this._root;
      var compare = this._compare;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return true;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return false;
    };
    /**
     * @param  {Visitor} visitor
     * @param  {*=}      ctx
     * @return {SplayTree}
     */
    Tree.prototype.forEach = function (visitor, ctx) {
      var current = this._root;
      var Q = []; /* Initialize stack s */
      var done = false;
      while (!done) {
        if (current !== nil) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length !== 0) {
            current = Q.pop();
            visitor.call(ctx, current);
            current = current.right;
          }
          else
            done = true;
        }
      }
      return this;
    };
    /**
     * Returns node at given index
     * @param  {number} index
     * @return {?Node}
     */
    Tree.prototype.at = function (index) {
      var current = this._root, done = false, i = 0;
      var Q = [];
      while (!done) {
        if (current !== nil) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length > 0) {
            current = Q.pop();
            if (i === index)
              return current;
            i++;
            current = current.right;
          }
          else
            done = true;
        }
      }
      return null;
    };
    /**
     * @param  {Key}      low
     * @param  {Key}      high
     * @param  {Function} fn
     * @param  {*?}       ctx
     * @return {SplayTree}
     */
    Tree.prototype.range = function (low, high, fn, ctx) {
      var Q = [];
      var compare = this._compare;
      var node = this._root, cmp;
      while (Q.length !== 0 || node) {
        if (node) {
          Q.push(node);
          node = node.left;
        }
        else {
          node = Q.pop();
          cmp = compare(node.key, high);
          if (cmp > 0) {
            break;
          }
          else if (compare(node.key, low) >= 0) {
            if (fn.call(ctx, node))
              return this; // stop if smth is returned
          }
          node = node.right;
        }
      }
      return this;
    };
    /**
     * Returns array of keys
     * @return {Array<Key>}
     */
    Tree.prototype.keys = function () {
      var keys = [];
      this.forEach(function (_a) {
        var key = _a.key;
        return keys.push(key);
      });
      return keys;
    };
    /**
     * Returns array of all the data in the nodes
     * @return {Array<Value>}
     */
    Tree.prototype.values = function () {
      var values = [];
      this.forEach(function (_a) {
        var data = _a.data;
        return values.push(data);
      });
      return values;
    };
    /**
     * @param  {Node}   d
     * @return {Node|nil}
     */
    Tree.prototype.next = function (d) {
      var root = this._root;
      var successor = nil;
      if (d.right !== nil) {
        successor = d.right;
        while (successor.left !== nil)
          successor = successor.left;
        return successor;
      }
      var comparator = this._compare;
      while (root !== nil) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0) {
          successor = root;
          root = root.left;
        }
        else
          root = root.right;
      }
      return successor === nil ? null : successor;
    };
    /**
     * @param  {Node} d
     * @return {Node|nil}
     */
    Tree.prototype.prev = function (d) {
      var root = this._root;
      var predecessor = nil;
      if (d.left !== nil) {
        predecessor = d.left;
        while (predecessor.right !== nil)
          predecessor = predecessor.right;
        return predecessor;
      }
      var comparator = this._compare;
      while (root !== nil) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          root = root.left;
        else {
          predecessor = root;
          root = root.right;
        }
      }
      return predecessor === nil ? null : predecessor;
    };
    Tree.prototype.clear = function () {
      this._root = nil;
      this._size = 0;
      return this;
    };
    Tree.nil = nil;
    return Tree;
  }());
  return Tree
})()`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    t.load(arr);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    var append = arr[0] == 72992;
    t.load(arr);
    // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    if (append) console.log(q);
    for (let i = 0; i < q; i++) {
        if (append) console.log('???');
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (append) console.log(type, x, arr.includes(x));
        if (type)
            t.insert(x);
        else
            t.remove(x);
        if(append) console.log("???2");
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    t.load(arr);
    // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new AVLTree();
    var tdif = new AVLTree();
    t.load(arr);
    tdif.load(Array(n - 1).fill(0).map((v, i) => arr[i + 1] - arr[i]));
    console.log(t.max() - t.min() - tdif.max());
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.remove(nextNode.key - prevNode.key);
                tdif.insert(nextNode.key - node.key);
                tdif.insert(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.insert(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.insert(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.insert(nextNode.key - prevNode.key);
                tdif.remove(nextNode.key - node.key);
                tdif.remove(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.remove(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.remove(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(t.max() - t.min() - tdif.max());
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
var AVLTree = eval(`
(function () { 'use strict';

  /**
   * Prints tree horizontally
   * @param  {Node}                       root
   * @param  {Function(node:Node):String} [printNode]
   * @return {String}
   */
  function print (root, printNode) {
    if ( printNode === void 0 ) printNode = function (n) { return n.key; };

    var out = [];
    row(root, '', true, function (v) { return out.push(v); }, printNode);
    return out.join('');
  }

  /**
   * Is the tree balanced (none of the subtrees differ in height by more than 1)
   * @param  {Node}    root
   * @return {Boolean}
   */
  function isBalanced(root) {
    if (root === null) { return true; } // If node is empty then return true

    // Get the height of left and right sub trees
    var lh = height(root.left);
    var rh = height(root.right);

    if (Math.abs(lh - rh) <= 1 &&
        isBalanced(root.left)  &&
        isBalanced(root.right)) { return true; }

    // If we reach here then tree is not height-balanced
    return false;
  }

  /**
   * The function Compute the 'height' of a tree.
   * Height is the number of nodes along the longest path
   * from the root node down to the farthest leaf node.
   *
   * @param  {Node} node
   * @return {Number}
   */
  function height(node) {
    return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
  }

  function loadRecursive (parent, keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key    = keys[middle];
      var data   = values[middle];
      var node   = { key: key, data: data, parent: parent };
      node.left    = loadRecursive(node, keys, values, start, middle);
      node.right   = loadRecursive(node, keys, values, middle + 1, end);
      return node;
    }
    return null;
  }

  function markBalance(node) {
    if (node === null) { return 0; }
    var lh = markBalance(node.left);
    var rh = markBalance(node.right);

    node.balanceFactor = lh - rh;
    return Math.max(lh, rh) + 1;
  }

  function sort(keys, values, left, right, compare) {
    if (left >= right) { return; }

    // eslint-disable-next-line no-bitwise
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;

    // eslint-disable-next-line no-constant-condition
    while (true) {
      do { i++; } while (compare(keys[i], pivot) < 0);
      do { j--; } while (compare(keys[j], pivot) > 0);
      if (i >= j) { break; }

      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;

      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }

    sort(keys, values,  left,     j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  // function createNode (parent, left, right, height, key, data) {
  //   return { parent, left, right, balanceFactor: height, key, data };
  // }

  /**
   * @typedef {{
   *   parent:        ?Node,
   *   left:          ?Node,
   *   right:         ?Node,
   *   balanceFactor: number,
   *   key:           Key,
   *   data:          Value
   * }} Node
   */

  /**
   * @typedef {*} Key
   */

  /**
   * @typedef {*} Value
   */

  /**
   * Default comparison function
   * @param {Key} a
   * @param {Key} b
   * @returns {number}
   */
  function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }

  /**
   * Single left rotation
   * @param  {Node} node
   * @return {Node}
   */
  function rotateLeft (node) {
    var rightNode = node.right;
    node.right    = rightNode.left;

    if (rightNode.left) { rightNode.left.parent = node; }

    rightNode.parent = node.parent;
    if (rightNode.parent) {
      if (rightNode.parent.left === node) {
        rightNode.parent.left = rightNode;
      } else {
        rightNode.parent.right = rightNode;
      }
    }

    node.parent    = rightNode;
    rightNode.left = node;

    node.balanceFactor += 1;
    if (rightNode.balanceFactor < 0) {
      node.balanceFactor -= rightNode.balanceFactor;
    }

    rightNode.balanceFactor += 1;
    if (node.balanceFactor > 0) {
      rightNode.balanceFactor += node.balanceFactor;
    }
    return rightNode;
  }

  function rotateRight (node) {
    var leftNode = node.left;
    node.left = leftNode.right;
    if (node.left) { node.left.parent = node; }

    leftNode.parent = node.parent;
    if (leftNode.parent) {
      if (leftNode.parent.left === node) {
        leftNode.parent.left = leftNode;
      } else {
        leftNode.parent.right = leftNode;
      }
    }

    node.parent    = leftNode;
    leftNode.right = node;

    node.balanceFactor -= 1;
    if (leftNode.balanceFactor > 0) {
      node.balanceFactor -= leftNode.balanceFactor;
    }

    leftNode.balanceFactor -= 1;
    if (node.balanceFactor < 0) {
      leftNode.balanceFactor += node.balanceFactor;
    }

    return leftNode;
  }

  // function leftBalance (node) {
  //   if (node.left.balanceFactor === -1) rotateLeft(node.left);
  //   return rotateRight(node);
  // }

  // function rightBalance (node) {
  //   if (node.right.balanceFactor === 1) rotateRight(node.right);
  //   return rotateLeft(node);
  // }

  var AVLTree = function AVLTree (comparator, noDuplicates) {
    if ( noDuplicates === void 0 ) noDuplicates = false;

    this._comparator = comparator || DEFAULT_COMPARE;
    this._root = null;
    this._size = 0;
    this._noDuplicates = !!noDuplicates;
  };

  var prototypeAccessors = { size: { configurable: true } };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.destroy = function destroy () {
    return this.clear();
  };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.clear = function clear () {
    this._root = null;
    this._size = 0;
    return this;
  };

  /**
   * Number of nodes
   * @return {number}
   */
  prototypeAccessors.size.get = function () {
    return this._size;
  };

  /**
   * Whether the tree contains a node with the given key
   * @param{Key} key
   * @return {boolean} true/false
   */
  AVLTree.prototype.contains = function contains (key) {
    if (this._root){
      var node     = this._root;
      var comparator = this._comparator;
      while (node){
        var cmp = comparator(key, node.key);
        if    (cmp === 0) { return true; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    }
    return false;
  };

  /* eslint-disable class-methods-use-this */

  /**
   * Successor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.next = function next (node) {
    var successor = node;
    if (successor) {
      if (successor.right) {
        successor = successor.right;
        while (successor.left) { successor = successor.left; }
      } else {
        successor = node.parent;
        while (successor && successor.right === node) {
          node = successor; successor = successor.parent;
        }
      }
    }
    return successor;
  };

  /**
   * Predecessor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.prev = function prev (node) {
    var predecessor = node;
    if (predecessor) {
      if (predecessor.left) {
        predecessor = predecessor.left;
        while (predecessor.right) { predecessor = predecessor.right; }
      } else {
        predecessor = node.parent;
        while (predecessor && predecessor.left === node) {
          node = predecessor;
          predecessor = predecessor.parent;
        }
      }
    }
    return predecessor;
  };
  /* eslint-enable class-methods-use-this */

  /**
   * Callback for forEach
   * @callback forEachCallback
   * @param {Node} node
   * @param {number} index
   */

  /**
   * @param{forEachCallback} callback
   * @return {AVLTree}
   */
  AVLTree.prototype.forEach = function forEach (callback) {
    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      // Reach the left most Node of the current Node
      if (current) {
        // Place pointer to a tree node on the stack
        // before traversing the node's left subtree
        s.push(current);
        current = current.left;
      } else {
        // BackTrack from the empty subtree and visit the Node
        // at the top of the stack; however, if the stack is
        // empty you are done
        if (s.length > 0) {
          current = s.pop();
          callback(current, i++);

          // We have visited the node and its left
          // subtree. Now, it's right subtree's turn
          current = current.right;
        } else { done = true; }
      }
    }
    return this;
  };

  AVLTree.prototype.range = function range (low, high, fn, ctx) {
      var this$1 = this;

    var Q = [];
    var compare = this._comparator;
    var node = this._root, cmp;

    while (Q.length !== 0 || node) {
      if (node) {
        Q.push(node);
        node = node.left;
      } else {
        node = Q.pop();
        cmp = compare(node.key, high);
        if (cmp > 0) {
          break;
        } else if (compare(node.key, low) >= 0) {
          if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned
        }
        node = node.right;
      }
    }
    return this;
  };

  /**
   * Returns all keys in order
   * @return {Array<Key>}
   */
  AVLTree.prototype.keys = function keys () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.key);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  AVLTree.prototype.values = function values () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.data);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  /**
   * Returns node at given index
   * @param{number} index
   * @return {?Node}
   */
  AVLTree.prototype.at = function at (index) {
    // removed after a consideration, more misleading than useful
    // index = index % this.size;
    // if (index < 0) index = this.size - index;

    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          if (i === index) { return current; }
          i++;
          current = current.right;
        } else { done = true; }
      }
    }
    return null;
  };

  /**
   * Returns node with the minimum key
   * @return {?Node}
   */
  AVLTree.prototype.minNode = function minNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node;
  };

  /**
   * Returns node with the max key
   * @return {?Node}
   */
  AVLTree.prototype.maxNode = function maxNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node;
  };

  /**
   * Min key
   * @return {?Key}
   */
  AVLTree.prototype.min = function min () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node.key;
  };

  /**
   * Max key
   * @return {?Key}
   */
  AVLTree.prototype.max = function max () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node.key;
  };

  /**
   * @return {boolean} true/false
   */
  AVLTree.prototype.isEmpty = function isEmpty () {
    return !this._root;
  };

  /**
   * Removes and returns the node with smallest key
   * @return {?Node}
   */
  AVLTree.prototype.pop = function pop () {
    var node = this._root, returnValue = null;
    if (node) {
      while (node.left) { node = node.left; }
      returnValue = { key: node.key, data: node.data };
      this.remove(node.key);
    }
    return returnValue;
  };

  /**
   * Find node by key
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.find = function find (key) {
    var root = this._root;
    // if (root === null)  return null;
    // if (key === root.key) return root;

    var subtree = root, cmp;
    var compare = this._comparator;
    while (subtree) {
      cmp = compare(key, subtree.key);
      if    (cmp === 0) { return subtree; }
      else if (cmp < 0) { subtree = subtree.left; }
      else              { subtree = subtree.right; }
    }

    return null;
  };

  /**
   * Insert a node into the tree
   * @param{Key} key
   * @param{Value} [data]
   * @return {?Node}
   */
  AVLTree.prototype.insert = function insert (key, data) {
      var this$1 = this;

    if (!this._root) {
      this._root = {
        parent: null, left: null, right: null, balanceFactor: 0,
        key: key, data: data
      };
      this._size++;
      return this._root;
    }

    var compare = this._comparator;
    var node  = this._root;
    var parent= null;
    var cmp   = 0;

    if (this._noDuplicates) {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp === 0) { return null; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    } else {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp <= 0){ node = node.left; } //return null;
        else              { node = node.right; }
      }
    }

    var newNode = {
      left: null,
      right: null,
      balanceFactor: 0,
      parent: parent, key: key, data: data
    };
    var newRoot;
    if (cmp <= 0) { parent.left= newNode; }
    else       { parent.right = newNode; }

    while (parent) {
      cmp = compare(parent.key, key);
      if (cmp < 0) { parent.balanceFactor -= 1; }
      else       { parent.balanceFactor += 1; }

      if      (parent.balanceFactor === 0) { break; }
      else if (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      }
      parent = parent.parent;
    }

    this._size++;
    return newNode;
  };

  /**
   * Removes the node from the tree. If not found, returns null.
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.remove = function remove (key) {
      var this$1 = this;

    if (!this._root) { return null; }

    var node = this._root;
    var compare = this._comparator;
    var cmp = 0;

    while (node) {
      cmp = compare(key, node.key);
      if    (cmp === 0) { break; }
      else if (cmp < 0) { node = node.left; }
      else              { node = node.right; }
    }
    if (!node) { return null; }

    var returnValue = node.key;
    var max, min;

    if (node.left) {
      max = node.left;

      while (max.left || max.right) {
        while (max.right) { max = max.right; }

        node.key = max.key;
        node.data = max.data;
        if (max.left) {
          node = max;
          max = max.left;
        }
      }

      node.key= max.key;
      node.data = max.data;
      node = max;
    }

    if (node.right) {
      min = node.right;

      while (min.left || min.right) {
        while (min.left) { min = min.left; }

        node.key= min.key;
        node.data = min.data;
        if (min.right) {
          node = min;
          min = min.right;
        }
      }

      node.key= min.key;
      node.data = min.data;
      node = min;
    }

    var parent = node.parent;
    var pp   = node;
    var newRoot;

    while (parent) {
      if (parent.left === pp) { parent.balanceFactor -= 1; }
      else                  { parent.balanceFactor += 1; }

      if      (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      }

      if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }

      pp   = parent;
      parent = parent.parent;
    }

    if (node.parent) {
      if (node.parent.left === node) { node.parent.left= null; }
      else                         { node.parent.right = null; }
    }

    if (node === this._root) { this._root = null; }

    this._size--;
    return returnValue;
  };

  /**
   * Bulk-load items
   * @param{Array<Key>}keys
   * @param{Array<Value>}[values]
   * @return {AVLTree}
   */
  AVLTree.prototype.load = function load (keys, values, presort) {
      if ( keys === void 0 ) keys = [];
      if ( values === void 0 ) values = [];

    if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }
    var size = keys.length;
    if (presort) { sort(keys, values, 0, size - 1, this._comparator); }
    this._root = loadRecursive(null, keys, values, 0, size);
    markBalance(this._root);
    this._size = size;
    return this;
  };

  /**
   * Returns true if the tree is balanced
   * @return {boolean}
   */
  AVLTree.prototype.isBalanced = function isBalanced$1 () {
    return isBalanced(this._root);
  };

  /**
   * String representation of the tree - primitive horizontal print-out
   * @param{Function(Node):string} [printNode]
   * @return {string}
   */
  AVLTree.prototype.toString = function toString (printNode) {
    return print(this._root, printNode);
  };

  Object.defineProperties( AVLTree.prototype, prototypeAccessors );

  AVLTree.default = AVLTree;

  return AVLTree;

})()
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new SplayTree();
    var tdif = new SplayTree();
    for (let i = 0; i < n; i++) {
        t.insert(arr[i]);
        if (i > 0)
            tdif.insert(arr[i] - arr[i - 1]);
    }
    console.log(t.max() - t.min() - tdif.max());
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.remove(nextNode.key - prevNode.key);
                tdif.insert(nextNode.key - node.key);
                tdif.insert(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.insert(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.insert(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.insert(nextNode.key - prevNode.key);
                tdif.remove(nextNode.key - node.key);
                tdif.remove(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.remove(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.remove(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(t.max() - t.min() - tdif.max());
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
var SplayTree = eval(`
(function () {
  var Node = /** @class */ (function () {
    function Node(key, data) {
      this.next = null;
      this.key = key;
      this.data = data;
      this.left = null;
      this.right = null;
    }
    return Node;
  }());

  /* follows "An implementation of top-down splaying"
   * by D. Sleator <sleator@cs.cmu.edu> March 1992
   */
  function DEFAULT_COMPARE(a, b) {
    return a > b ? 1 : a < b ? -1 : 0;
  }
  /**
   * Simple top down splay, not requiring i to be in the tree t.
   */
  function splay(i, t, comparator) {
    var N = new Node(null, null);
    var l = N;
    var r = N;
    while (true) {
      var cmp = comparator(i, t.key);
      //if (i < t.key) {
      if (cmp < 0) {
        if (t.left === null)
          break;
        //if (i < t.left.key) {
        if (comparator(i, t.left.key) < 0) {
          var y = t.left; /* rotate right */
          t.left = y.right;
          y.right = t;
          t = y;
          if (t.left === null)
            break;
        }
        r.left = t; /* link right */
        r = t;
        t = t.left;
        //} else if (i > t.key) {
      }
      else if (cmp > 0) {
        if (t.right === null)
          break;
        //if (i > t.right.key) {
        if (comparator(i, t.right.key) > 0) {
          var y = t.right; /* rotate left */
          t.right = y.left;
          y.left = t;
          t = y;
          if (t.right === null)
            break;
        }
        l.right = t; /* link left */
        l = t;
        t = t.right;
      }
      else
        break;
    }
    /* assemble */
    l.right = t.left;
    r.left = t.right;
    t.left = N.right;
    t.right = N.left;
    return t;
  }
  function insert(i, data, t, comparator) {
    var node = new Node(i, data);
    if (t === null) {
      node.left = node.right = null;
      return node;
    }
    t = splay(i, t, comparator);
    var cmp = comparator(i, t.key);
    if (cmp < 0) {
      node.left = t.left;
      node.right = t;
      t.left = null;
    }
    else if (cmp >= 0) {
      node.right = t.right;
      node.left = t;
      t.right = null;
    }
    return node;
  }
  function split(key, v, comparator) {
    var left = null;
    var right = null;
    if (v) {
      v = splay(key, v, comparator);
      var cmp = comparator(v.key, key);
      if (cmp === 0) {
        left = v.left;
        right = v.right;
      }
      else if (cmp < 0) {
        right = v.right;
        v.right = null;
        left = v;
      }
      else {
        left = v.left;
        v.left = null;
        right = v;
      }
    }
    return { left: left, right: right };
  }
  function merge(left, right, comparator) {
    if (right === null)
      return left;
    if (left === null)
      return right;
    right = splay(left.key, right, comparator);
    right.left = left;
    return right;
  }
  var Tree = /** @class */ (function () {
    function Tree(comparator) {
      if (comparator === void 0) { comparator = DEFAULT_COMPARE; }
      this._root = null;
      this._size = 0;
      this._comparator = comparator;
    }
    /**
     * Inserts a key, allows duplicates
     */
    Tree.prototype.insert = function (key, data) {
      this._size++;
      return this._root = insert(key, data, this._root, this._comparator);
    };
    /**
     * Adds a key, if it is not present in the tree
     */
    Tree.prototype.add = function (key, data) {
      var node = new Node(key, data);
      if (this._root === null) {
        node.left = node.right = null;
        this._size++;
        this._root = node;
      }
      var comparator = this._comparator;
      var t = splay(key, this._root, comparator);
      var cmp = comparator(key, t.key);
      if (cmp === 0)
        this._root = t;
      else {
        if (cmp < 0) {
          node.left = t.left;
          node.right = t;
          t.left = null;
        }
        else if (cmp > 0) {
          node.right = t.right;
          node.left = t;
          t.right = null;
        }
        this._size++;
        this._root = node;
      }
      return this._root;
    };
    /**
     * @param  {Key} key
     * @return {Node|null}
     */
    Tree.prototype.remove = function (key) {
      this._root = this._remove(key, this._root, this._comparator);
    };
    /**
     * Deletes i from the tree if it's there
     */
    Tree.prototype._remove = function (i, t, comparator) {
      var x;
      if (t === null)
        return null;
      t = splay(i, t, comparator);
      var cmp = comparator(i, t.key);
      if (cmp === 0) { /* found it */
        if (t.left === null) {
          x = t.right;
        }
        else {
          x = splay(i, t.left, comparator);
          x.right = t.right;
        }
        this._size--;
        return x;
      }
      return t; /* It wasn't there */
    };
    /**
     * Removes and returns the node with smallest key
     */
    Tree.prototype.pop = function () {
      var node = this._root;
      if (node) {
        while (node.left)
          node = node.left;
        this._root = splay(node.key, this._root, this._comparator);
        this._root = this._remove(node.key, this._root, this._comparator);
        return { key: node.key, data: node.data };
      }
      return null;
    };
    /**
     * Find without splaying
     */
    Tree.prototype.findStatic = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return current;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return null;
    };
    Tree.prototype.find = function (key) {
      if (this._root) {
        this._root = splay(key, this._root, this._comparator);
        if (this._comparator(key, this._root.key) !== 0)
          return null;
      }
      return this._root;
    };
    Tree.prototype.contains = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return true;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return false;
    };
    Tree.prototype.forEach = function (visitor, ctx) {
      var current = this._root;
      var Q = []; /* Initialize stack s */
      var done = false;
      while (!done) {
        if (current !== null) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length !== 0) {
            current = Q.pop();
            visitor.call(ctx, current);
            current = current.right;
          }
          else
            done = true;
        }
      }
      return this;
    };

    Tree.prototype.range = function (low, high, fn, ctx) {
      var Q = [];
      var compare = this._comparator;
      var node = this._root;
      var cmp;
      while (Q.length !== 0 || node) {
        if (node) {
          Q.push(node);
          node = node.left;
        }
        else {
          node = Q.pop();
          cmp = compare(node.key, high);
          if (cmp > 0) {
            break;
          }
          else if (compare(node.key, low) >= 0) {
            if (fn.call(ctx, node))
              return this; // stop if smth is returned
          }
          node = node.right;
        }
      }
      return this;
    };
    /**
     * Returns array of keys
     */
    Tree.prototype.keys = function () {
      var keys = [];
      this.forEach(function (_a) {
        var key = _a.key;
        return keys.push(key);
      });
      return keys;
    };
    /**
     * Returns array of all the data in the nodes
     */
    Tree.prototype.values = function () {
      var values = [];
      this.forEach(function (_a) {
        var data = _a.data;
        return values.push(data);
      });
      return values;
    };
    Tree.prototype.min = function () {
      if (this._root)
        return this.minNode(this._root).key;
      return null;
    };
    Tree.prototype.max = function () {
      if (this._root)
        return this.maxNode(this._root).key;
      return null;
    };
    Tree.prototype.minNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.left)
          t = t.left;
      return t;
    };
    Tree.prototype.maxNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.right)
          t = t.right;
      return t;
    };
    /**
     * Returns node at given index
     */
    Tree.prototype.at = function (index) {
      var current = this._root;
      var done = false;
      var i = 0;
      var Q = [];
      while (!done) {
        if (current) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length > 0) {
            current = Q.pop();
            if (i === index)
              return current;
            i++;
            current = current.right;
          }
          else
            done = true;
        }
      }
      return null;
    };
    Tree.prototype.next = function (d) {
      var root = this._root;
      var successor = null;
      if (d.right) {
        successor = d.right;
        while (successor.left)
          successor = successor.left;
        return successor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0) {
          successor = root;
          root = root.left;
        }
        else
          root = root.right;
      }
      return successor;
    };
    Tree.prototype.prev = function (d) {
      var root = this._root;
      var predecessor = null;
      if (d.left !== null) {
        predecessor = d.left;
        while (predecessor.right)
          predecessor = predecessor.right;
        return predecessor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          root = root.left;
        else {
          predecessor = root;
          root = root.right;
        }
      }
      return predecessor;
    };
    Tree.prototype.clear = function () {
      this._root = null;
      this._size = 0;
      return this;
    };
    Tree.prototype.toList = function () {
      return toList(this._root);
    };
    /**
     * Bulk-load items. Both array have to be same size
     */
    Tree.prototype.load = function (keys, values, presort) {
      if (values === void 0) { values = []; }
      if (presort === void 0) { presort = false; }
      var size = keys.length;
      var comparator = this._comparator;
      // sort if needed
      if (presort)
        sort(keys, values, 0, size - 1, comparator);
      if (this._root === null) { // empty tree
        this._root = loadRecursive(keys, values, 0, size);
        this._size = size;
      }
      else { // that re-builds the whole tree from two in-order traversals
        var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);
        size = this._size + size;
        this._root = sortedListToBST({ head: mergedList }, 0, size);
      }
      return this;
    };
    Tree.prototype.isEmpty = function () { return this._root === null; };
    Object.defineProperty(Tree.prototype, "size", {
      get: function () { return this._size; },
      enumerable: true,
      configurable: true
    });
    Object.defineProperty(Tree.prototype, "root", {
      get: function () { return this._root; },
      enumerable: true,
      configurable: true
    });
    Tree.prototype.toString = function (printNode) {
      if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }
      var out = [];
      printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);
      return out.join('');
    };
    Tree.prototype.update = function (key, newKey, newData) {
      var comparator = this._comparator;
      var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;
      if (comparator(key, newKey) < 0) {
        right = insert(newKey, newData, right, comparator);
      }
      else {
        left = insert(newKey, newData, left, comparator);
      }
      this._root = merge(left, right, comparator);
    };
    Tree.prototype.split = function (key) {
      return split(key, this._root, this._comparator);
    };
    return Tree;
  }());
  function loadRecursive(keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key = keys[middle];
      var data = values[middle];
      var node = new Node(key, data);
      node.left = loadRecursive(keys, values, start, middle);
      node.right = loadRecursive(keys, values, middle + 1, end);
      return node;
    }
    return null;
  }
  function createList(keys, values) {
    var head = new Node(null, null);
    var p = head;
    for (var i = 0; i < keys.length; i++) {
      p = p.next = new Node(keys[i], values[i]);
    }
    p.next = null;
    return head.next;
  }
  function toList(root) {
    var current = root;
    var Q = [];
    var done = false;
    var head = new Node(null, null);
    var p = head;
    while (!done) {
      if (current) {
        Q.push(current);
        current = current.left;
      }
      else {
        if (Q.length > 0) {
          current = p = p.next = Q.pop();
          current = current.right;
        }
        else
          done = true;
      }
    }
    p.next = null; // that'll work even if the tree was empty
    return head.next;
  }
  function sortedListToBST(list, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var left = sortedListToBST(list, start, middle);
      var root = list.head;
      root.left = left;
      list.head = list.head.next;
      root.right = sortedListToBST(list, middle + 1, end);
      return root;
    }
    return null;
  }
  function mergeLists(l1, l2, compare) {
    var head = new Node(null, null); // dummy
    var p = head;
    var p1 = l1;
    var p2 = l2;
    while (p1 !== null && p2 !== null) {
      if (compare(p1.key, p2.key) < 0) {
        p.next = p1;
        p1 = p1.next;
      }
      else {
        p.next = p2;
        p2 = p2.next;
      }
      p = p.next;
    }
    if (p1 !== null) {
      p.next = p1;
    }
    else if (p2 !== null) {
      p.next = p2;
    }
    return head.next;
  }
  function sort(keys, values, left, right, compare) {
    if (left >= right)
      return;
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;
    while (true) {
      do
        i++;
      while (compare(keys[i], pivot) < 0);
      do
        j--;
      while (compare(keys[j], pivot) > 0);
      if (i >= j)
        break;
      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;
      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }
    sort(keys, values, left, j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  return Tree;

})();
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new SplayTree();
    var tdif = new SplayTree();
    for (let i = 0; i < n; i++) {
        t.insert(arr[i]);
        if (i > 0)
            tdif.insert(arr[i] - arr[i - 1]);
    }
    console.log(t.max() - t.min() - tdif.max());
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.remove(nextNode.key - prevNode.key);
                tdif.insert(nextNode.key - node.key);
                tdif.insert(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.insert(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.insert(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                tdif.insert(nextNode.key - prevNode.key);
                tdif.remove(nextNode.key - node.key);
                tdif.remove(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                tdif.remove(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                tdif.remove(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(t.max() - t.min() - tdif.max());
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
// var AVLTree = eval(`
// (function () { 'use strict';
//   /**
//    * Prints tree horizontally
//    * @param  {Node}                       root
//    * @param  {Function(node:Node):String} [printNode]
//    * @return {String}
//    */
//   function print (root, printNode) {
//     if ( printNode === void 0 ) printNode = function (n) { return n.key; };
//     var out = [];
//     row(root, '', true, function (v) { return out.push(v); }, printNode);
//     return out.join('');
//   }
//   /**
//    * Is the tree balanced (none of the subtrees differ in height by more than 1)
//    * @param  {Node}    root
//    * @return {Boolean}
//    */
//   function isBalanced(root) {
//     if (root === null) { return true; } // If node is empty then return true
//     // Get the height of left and right sub trees
//     var lh = height(root.left);
//     var rh = height(root.right);
//     if (Math.abs(lh - rh) <= 1 &&
//         isBalanced(root.left)  &&
//         isBalanced(root.right)) { return true; }
//     // If we reach here then tree is not height-balanced
//     return false;
//   }
//   /**
//    * The function Compute the 'height' of a tree.
//    * Height is the number of nodes along the longest path
//    * from the root node down to the farthest leaf node.
//    *
//    * @param  {Node} node
//    * @return {Number}
//    */
//   function height(node) {
//     return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
//   }
//   function loadRecursive (parent, keys, values, start, end) {
//     var size = end - start;
//     if (size > 0) {
//       var middle = start + Math.floor(size / 2);
//       var key    = keys[middle];
//       var data   = values[middle];
//       var node   = { key: key, data: data, parent: parent };
//       node.left    = loadRecursive(node, keys, values, start, middle);
//       node.right   = loadRecursive(node, keys, values, middle + 1, end);
//       return node;
//     }
//     return null;
//   }
//   function markBalance(node) {
//     if (node === null) { return 0; }
//     var lh = markBalance(node.left);
//     var rh = markBalance(node.right);
//     node.balanceFactor = lh - rh;
//     return Math.max(lh, rh) + 1;
//   }
//   function sort(keys, values, left, right, compare) {
//     if (left >= right) { return; }
//     // eslint-disable-next-line no-bitwise
//     var pivot = keys[(left + right) >> 1];
//     var i = left - 1;
//     var j = right + 1;
//     // eslint-disable-next-line no-constant-condition
//     while (true) {
//       do { i++; } while (compare(keys[i], pivot) < 0);
//       do { j--; } while (compare(keys[j], pivot) > 0);
//       if (i >= j) { break; }
//       var tmp = keys[i];
//       keys[i] = keys[j];
//       keys[j] = tmp;
//       tmp = values[i];
//       values[i] = values[j];
//       values[j] = tmp;
//     }
//     sort(keys, values,  left,     j, compare);
//     sort(keys, values, j + 1, right, compare);
//   }
//   // function createNode (parent, left, right, height, key, data) {
//   //   return { parent, left, right, balanceFactor: height, key, data };
//   // }
//   /**
//    * @typedef {{
//    *   parent:        ?Node,
//    *   left:          ?Node,
//    *   right:         ?Node,
//    *   balanceFactor: number,
//    *   key:           Key,
//    *   data:          Value
//    * }} Node
//    */
//   /**
//    * @typedef {*} Key
//    */
//   /**
//    * @typedef {*} Value
//    */
//   /**
//    * Default comparison function
//    * @param {Key} a
//    * @param {Key} b
//    * @returns {number}
//    */
//   function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }
//   /**
//    * Single left rotation
//    * @param  {Node} node
//    * @return {Node}
//    */
//   function rotateLeft (node) {
//     var rightNode = node.right;
//     node.right    = rightNode.left;
//     if (rightNode.left) { rightNode.left.parent = node; }
//     rightNode.parent = node.parent;
//     if (rightNode.parent) {
//       if (rightNode.parent.left === node) {
//         rightNode.parent.left = rightNode;
//       } else {
//         rightNode.parent.right = rightNode;
//       }
//     }
//     node.parent    = rightNode;
//     rightNode.left = node;
//     node.balanceFactor += 1;
//     if (rightNode.balanceFactor < 0) {
//       node.balanceFactor -= rightNode.balanceFactor;
//     }
//     rightNode.balanceFactor += 1;
//     if (node.balanceFactor > 0) {
//       rightNode.balanceFactor += node.balanceFactor;
//     }
//     return rightNode;
//   }
//   function rotateRight (node) {
//     var leftNode = node.left;
//     node.left = leftNode.right;
//     if (node.left) { node.left.parent = node; }
//     leftNode.parent = node.parent;
//     if (leftNode.parent) {
//       if (leftNode.parent.left === node) {
//         leftNode.parent.left = leftNode;
//       } else {
//         leftNode.parent.right = leftNode;
//       }
//     }
//     node.parent    = leftNode;
//     leftNode.right = node;
//     node.balanceFactor -= 1;
//     if (leftNode.balanceFactor > 0) {
//       node.balanceFactor -= leftNode.balanceFactor;
//     }
//     leftNode.balanceFactor -= 1;
//     if (node.balanceFactor < 0) {
//       leftNode.balanceFactor += node.balanceFactor;
//     }
//     return leftNode;
//   }
//   // function leftBalance (node) {
//   //   if (node.left.balanceFactor === -1) rotateLeft(node.left);
//   //   return rotateRight(node);
//   // }
//   // function rightBalance (node) {
//   //   if (node.right.balanceFactor === 1) rotateRight(node.right);
//   //   return rotateLeft(node);
//   // }
//   var AVLTree = function AVLTree (comparator, noDuplicates) {
//     if ( noDuplicates === void 0 ) noDuplicates = false;
//     this._comparator = comparator || DEFAULT_COMPARE;
//     this._root = null;
//     this._size = 0;
//     this._noDuplicates = !!noDuplicates;
//   };
//   var prototypeAccessors = { size: { configurable: true } };
//   /**
//    * Clear the tree
//    * @return {AVLTree}
//    */
//   AVLTree.prototype.destroy = function destroy () {
//     return this.clear();
//   };
//   /**
//    * Clear the tree
//    * @return {AVLTree}
//    */
//   AVLTree.prototype.clear = function clear () {
//     this._root = null;
//     this._size = 0;
//     return this;
//   };
//   /**
//    * Number of nodes
//    * @return {number}
//    */
//   prototypeAccessors.size.get = function () {
//     return this._size;
//   };
//   /**
//    * Whether the tree contains a node with the given key
//    * @param{Key} key
//    * @return {boolean} true/false
//    */
//   AVLTree.prototype.contains = function contains (key) {
//     if (this._root){
//       var node     = this._root;
//       var comparator = this._comparator;
//       while (node){
//         var cmp = comparator(key, node.key);
//         if    (cmp === 0) { return true; }
//         else if (cmp < 0) { node = node.left; }
//         else              { node = node.right; }
//       }
//     }
//     return false;
//   };
//   /* eslint-disable class-methods-use-this */
//   /**
//    * Successor node
//    * @param{Node} node
//    * @return {?Node}
//    */
//   AVLTree.prototype.next = function next (node) {
//     var successor = node;
//     if (successor) {
//       if (successor.right) {
//         successor = successor.right;
//         while (successor.left) { successor = successor.left; }
//       } else {
//         successor = node.parent;
//         while (successor && successor.right === node) {
//           node = successor; successor = successor.parent;
//         }
//       }
//     }
//     return successor;
//   };
//   /**
//    * Predecessor node
//    * @param{Node} node
//    * @return {?Node}
//    */
//   AVLTree.prototype.prev = function prev (node) {
//     var predecessor = node;
//     if (predecessor) {
//       if (predecessor.left) {
//         predecessor = predecessor.left;
//         while (predecessor.right) { predecessor = predecessor.right; }
//       } else {
//         predecessor = node.parent;
//         while (predecessor && predecessor.left === node) {
//           node = predecessor;
//           predecessor = predecessor.parent;
//         }
//       }
//     }
//     return predecessor;
//   };
//   /* eslint-enable class-methods-use-this */
//   /**
//    * Callback for forEach
//    * @callback forEachCallback
//    * @param {Node} node
//    * @param {number} index
//    */
//   /**
//    * @param{forEachCallback} callback
//    * @return {AVLTree}
//    */
//   AVLTree.prototype.forEach = function forEach (callback) {
//     var current = this._root;
//     var s = [], done = false, i = 0;
//     while (!done) {
//       // Reach the left most Node of the current Node
//       if (current) {
//         // Place pointer to a tree node on the stack
//         // before traversing the node's left subtree
//         s.push(current);
//         current = current.left;
//       } else {
//         // BackTrack from the empty subtree and visit the Node
//         // at the top of the stack; however, if the stack is
//         // empty you are done
//         if (s.length > 0) {
//           current = s.pop();
//           callback(current, i++);
//           // We have visited the node and its left
//           // subtree. Now, it's right subtree's turn
//           current = current.right;
//         } else { done = true; }
//       }
//     }
//     return this;
//   };
//   AVLTree.prototype.range = function range (low, high, fn, ctx) {
//       var this$1 = this;
//     var Q = [];
//     var compare = this._comparator;
//     var node = this._root, cmp;
//     while (Q.length !== 0 || node) {
//       if (node) {
//         Q.push(node);
//         node = node.left;
//       } else {
//         node = Q.pop();
//         cmp = compare(node.key, high);
//         if (cmp > 0) {
//           break;
//         } else if (compare(node.key, low) >= 0) {
//           if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned
//         }
//         node = node.right;
//       }
//     }
//     return this;
//   };
//   /**
//    * Returns all keys in order
//    * @return {Array<Key>}
//    */
//   AVLTree.prototype.keys = function keys () {
//     var current = this._root;
//     var s = [], r = [], done = false;
//     while (!done) {
//       if (current) {
//         s.push(current);
//         current = current.left;
//       } else {
//         if (s.length > 0) {
//           current = s.pop();
//           r.push(current.key);
//           current = current.right;
//         } else { done = true; }
//       }
//     }
//     return r;
//   };
//   AVLTree.prototype.values = function values () {
//     var current = this._root;
//     var s = [], r = [], done = false;
//     while (!done) {
//       if (current) {
//         s.push(current);
//         current = current.left;
//       } else {
//         if (s.length > 0) {
//           current = s.pop();
//           r.push(current.data);
//           current = current.right;
//         } else { done = true; }
//       }
//     }
//     return r;
//   };
//   /**
//    * Returns node at given index
//    * @param{number} index
//    * @return {?Node}
//    */
//   AVLTree.prototype.at = function at (index) {
//     // removed after a consideration, more misleading than useful
//     // index = index % this.size;
//     // if (index < 0) index = this.size - index;
//     var current = this._root;
//     var s = [], done = false, i = 0;
//     while (!done) {
//       if (current) {
//         s.push(current);
//         current = current.left;
//       } else {
//         if (s.length > 0) {
//           current = s.pop();
//           if (i === index) { return current; }
//           i++;
//           current = current.right;
//         } else { done = true; }
//       }
//     }
//     return null;
//   };
//   /**
//    * Returns node with the minimum key
//    * @return {?Node}
//    */
//   AVLTree.prototype.minNode = function minNode () {
//     var node = this._root;
//     if (!node) { return null; }
//     while (node.left) { node = node.left; }
//     return node;
//   };
//   /**
//    * Returns node with the max key
//    * @return {?Node}
//    */
//   AVLTree.prototype.maxNode = function maxNode () {
//     var node = this._root;
//     if (!node) { return null; }
//     while (node.right) { node = node.right; }
//     return node;
//   };
//   /**
//    * Min key
//    * @return {?Key}
//    */
//   AVLTree.prototype.min = function min () {
//     var node = this._root;
//     if (!node) { return null; }
//     while (node.left) { node = node.left; }
//     return node.key;
//   };
//   /**
//    * Max key
//    * @return {?Key}
//    */
//   AVLTree.prototype.max = function max () {
//     var node = this._root;
//     if (!node) { return null; }
//     while (node.right) { node = node.right; }
//     return node.key;
//   };
//   /**
//    * @return {boolean} true/false
//    */
//   AVLTree.prototype.isEmpty = function isEmpty () {
//     return !this._root;
//   };
//   /**
//    * Removes and returns the node with smallest key
//    * @return {?Node}
//    */
//   AVLTree.prototype.pop = function pop () {
//     var node = this._root, returnValue = null;
//     if (node) {
//       while (node.left) { node = node.left; }
//       returnValue = { key: node.key, data: node.data };
//       this.remove(node.key);
//     }
//     return returnValue;
//   };
//   /**
//    * Find node by key
//    * @param{Key} key
//    * @return {?Node}
//    */
//   AVLTree.prototype.find = function find (key) {
//     var root = this._root;
//     // if (root === null)  return null;
//     // if (key === root.key) return root;
//     var subtree = root, cmp;
//     var compare = this._comparator;
//     while (subtree) {
//       cmp = compare(key, subtree.key);
//       if    (cmp === 0) { return subtree; }
//       else if (cmp < 0) { subtree = subtree.left; }
//       else              { subtree = subtree.right; }
//     }
//     return null;
//   };
//   /**
//    * Insert a node into the tree
//    * @param{Key} key
//    * @param{Value} [data]
//    * @return {?Node}
//    */
//   AVLTree.prototype.insert = function insert (key, data) {
//       var this$1 = this;
//     if (!this._root) {
//       this._root = {
//         parent: null, left: null, right: null, balanceFactor: 0,
//         key: key, data: data
//       };
//       this._size++;
//       return this._root;
//     }
//     var compare = this._comparator;
//     var node  = this._root;
//     var parent= null;
//     var cmp   = 0;
//     if (this._noDuplicates) {
//       while (node) {
//         cmp = compare(key, node.key);
//         parent = node;
//         if    (cmp === 0) { return null; }
//         else if (cmp < 0) { node = node.left; }
//         else              { node = node.right; }
//       }
//     } else {
//       while (node) {
//         cmp = compare(key, node.key);
//         parent = node;
//         if    (cmp <= 0){ node = node.left; } //return null;
//         else              { node = node.right; }
//       }
//     }
//     var newNode = {
//       left: null,
//       right: null,
//       balanceFactor: 0,
//       parent: parent, key: key, data: data
//     };
//     var newRoot;
//     if (cmp <= 0) { parent.left= newNode; }
//     else       { parent.right = newNode; }
//     while (parent) {
//       cmp = compare(parent.key, key);
//       if (cmp < 0) { parent.balanceFactor -= 1; }
//       else       { parent.balanceFactor += 1; }
//       if      (parent.balanceFactor === 0) { break; }
//       else if (parent.balanceFactor < -1) {
//         // inlined
//         //var newRoot = rightBalance(parent);
//         if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
//         newRoot = rotateLeft(parent);
//         if (parent === this$1._root) { this$1._root = newRoot; }
//         break;
//       } else if (parent.balanceFactor > 1) {
//         // inlined
//         // var newRoot = leftBalance(parent);
//         if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
//         newRoot = rotateRight(parent);
//         if (parent === this$1._root) { this$1._root = newRoot; }
//         break;
//       }
//       parent = parent.parent;
//     }
//     this._size++;
//     return newNode;
//   };
//   /**
//    * Removes the node from the tree. If not found, returns null.
//    * @param{Key} key
//    * @return {?Node}
//    */
//   AVLTree.prototype.remove = function remove (key) {
//       var this$1 = this;
//     if (!this._root) { return null; }
//     var node = this._root;
//     var compare = this._comparator;
//     var cmp = 0;
//     while (node) {
//       cmp = compare(key, node.key);
//       if    (cmp === 0) { break; }
//       else if (cmp < 0) { node = node.left; }
//       else              { node = node.right; }
//     }
//     if (!node) { return null; }
//     var returnValue = node.key;
//     var max, min;
//     if (node.left) {
//       max = node.left;
//       while (max.left || max.right) {
//         while (max.right) { max = max.right; }
//         node.key = max.key;
//         node.data = max.data;
//         if (max.left) {
//           node = max;
//           max = max.left;
//         }
//       }
//       node.key= max.key;
//       node.data = max.data;
//       node = max;
//     }
//     if (node.right) {
//       min = node.right;
//       while (min.left || min.right) {
//         while (min.left) { min = min.left; }
//         node.key= min.key;
//         node.data = min.data;
//         if (min.right) {
//           node = min;
//           min = min.right;
//         }
//       }
//       node.key= min.key;
//       node.data = min.data;
//       node = min;
//     }
//     var parent = node.parent;
//     var pp   = node;
//     var newRoot;
//     while (parent) {
//       if (parent.left === pp) { parent.balanceFactor -= 1; }
//       else                  { parent.balanceFactor += 1; }
//       if      (parent.balanceFactor < -1) {
//         // inlined
//         //var newRoot = rightBalance(parent);
//         if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
//         newRoot = rotateLeft(parent);
//         if (parent === this$1._root) { this$1._root = newRoot; }
//         parent = newRoot;
//       } else if (parent.balanceFactor > 1) {
//         // inlined
//         // var newRoot = leftBalance(parent);
//         if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
//         newRoot = rotateRight(parent);
//         if (parent === this$1._root) { this$1._root = newRoot; }
//         parent = newRoot;
//       }
//       if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }
//       pp   = parent;
//       parent = parent.parent;
//     }
//     if (node.parent) {
//       if (node.parent.left === node) { node.parent.left= null; }
//       else                         { node.parent.right = null; }
//     }
//     if (node === this._root) { this._root = null; }
//     this._size--;
//     return returnValue;
//   };
//   /**
//    * Bulk-load items
//    * @param{Array<Key>}keys
//    * @param{Array<Value>}[values]
//    * @return {AVLTree}
//    */
//   AVLTree.prototype.load = function load (keys, values, presort) {
//       if ( keys === void 0 ) keys = [];
//       if ( values === void 0 ) values = [];
//     if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }
//     var size = keys.length;
//     if (presort) { sort(keys, values, 0, size - 1, this._comparator); }
//     this._root = loadRecursive(null, keys, values, 0, size);
//     markBalance(this._root);
//     this._size = size;
//     return this;
//   };
//   /**
//    * Returns true if the tree is balanced
//    * @return {boolean}
//    */
//   AVLTree.prototype.isBalanced = function isBalanced$1 () {
//     return isBalanced(this._root);
//   };
//   /**
//    * String representation of the tree - primitive horizontal print-out
//    * @param{Function(Node):string} [printNode]
//    * @return {string}
//    */
//   AVLTree.prototype.toString = function toString (printNode) {
//     return print(this._root, printNode);
//   };
//   Object.defineProperties( AVLTree.prototype, prototypeAccessors );
//   AVLTree.default = AVLTree;
//   return AVLTree;
// })()
// `);
var SplayTree = eval(`
(function () {
  var Node = /** @class */ (function () {
    function Node(key, data) {
      this.next = null;
      this.key = key;
      this.data = data;
      this.left = null;
      this.right = null;
    }
    return Node;
  }());

  /* follows "An implementation of top-down splaying"
   * by D. Sleator <sleator@cs.cmu.edu> March 1992
   */
  function DEFAULT_COMPARE(a, b) {
    return a > b ? 1 : a < b ? -1 : 0;
  }
  /**
   * Simple top down splay, not requiring i to be in the tree t.
   */
  function splay(i, t, comparator) {
    var N = new Node(null, null);
    var l = N;
    var r = N;
    while (true) {
      var cmp = comparator(i, t.key);
      //if (i < t.key) {
      if (cmp < 0) {
        if (t.left === null)
          break;
        //if (i < t.left.key) {
        if (comparator(i, t.left.key) < 0) {
          var y = t.left; /* rotate right */
          t.left = y.right;
          y.right = t;
          t = y;
          if (t.left === null)
            break;
        }
        r.left = t; /* link right */
        r = t;
        t = t.left;
        //} else if (i > t.key) {
      }
      else if (cmp > 0) {
        if (t.right === null)
          break;
        //if (i > t.right.key) {
        if (comparator(i, t.right.key) > 0) {
          var y = t.right; /* rotate left */
          t.right = y.left;
          y.left = t;
          t = y;
          if (t.right === null)
            break;
        }
        l.right = t; /* link left */
        l = t;
        t = t.right;
      }
      else
        break;
    }
    /* assemble */
    l.right = t.left;
    r.left = t.right;
    t.left = N.right;
    t.right = N.left;
    return t;
  }
  function insert(i, data, t, comparator) {
    var node = new Node(i, data);
    if (t === null) {
      node.left = node.right = null;
      return node;
    }
    t = splay(i, t, comparator);
    var cmp = comparator(i, t.key);
    if (cmp < 0) {
      node.left = t.left;
      node.right = t;
      t.left = null;
    }
    else if (cmp >= 0) {
      node.right = t.right;
      node.left = t;
      t.right = null;
    }
    return node;
  }
  function split(key, v, comparator) {
    var left = null;
    var right = null;
    if (v) {
      v = splay(key, v, comparator);
      var cmp = comparator(v.key, key);
      if (cmp === 0) {
        left = v.left;
        right = v.right;
      }
      else if (cmp < 0) {
        right = v.right;
        v.right = null;
        left = v;
      }
      else {
        left = v.left;
        v.left = null;
        right = v;
      }
    }
    return { left: left, right: right };
  }
  function merge(left, right, comparator) {
    if (right === null)
      return left;
    if (left === null)
      return right;
    right = splay(left.key, right, comparator);
    right.left = left;
    return right;
  }
  var Tree = /** @class */ (function () {
    function Tree(comparator) {
      if (comparator === void 0) { comparator = DEFAULT_COMPARE; }
      this._root = null;
      this._size = 0;
      this._comparator = comparator;
    }
    /**
     * Inserts a key, allows duplicates
     */
    Tree.prototype.insert = function (key, data) {
      this._size++;
      return this._root = insert(key, data, this._root, this._comparator);
    };
    /**
     * Adds a key, if it is not present in the tree
     */
    Tree.prototype.add = function (key, data) {
      var node = new Node(key, data);
      if (this._root === null) {
        node.left = node.right = null;
        this._size++;
        this._root = node;
      }
      var comparator = this._comparator;
      var t = splay(key, this._root, comparator);
      var cmp = comparator(key, t.key);
      if (cmp === 0)
        this._root = t;
      else {
        if (cmp < 0) {
          node.left = t.left;
          node.right = t;
          t.left = null;
        }
        else if (cmp > 0) {
          node.right = t.right;
          node.left = t;
          t.right = null;
        }
        this._size++;
        this._root = node;
      }
      return this._root;
    };
    /**
     * @param  {Key} key
     * @return {Node|null}
     */
    Tree.prototype.remove = function (key) {
      this._root = this._remove(key, this._root, this._comparator);
    };
    /**
     * Deletes i from the tree if it's there
     */
    Tree.prototype._remove = function (i, t, comparator) {
      var x;
      if (t === null)
        return null;
      t = splay(i, t, comparator);
      var cmp = comparator(i, t.key);
      if (cmp === 0) { /* found it */
        if (t.left === null) {
          x = t.right;
        }
        else {
          x = splay(i, t.left, comparator);
          x.right = t.right;
        }
        this._size--;
        return x;
      }
      return t; /* It wasn't there */
    };
    /**
     * Removes and returns the node with smallest key
     */
    Tree.prototype.pop = function () {
      var node = this._root;
      if (node) {
        while (node.left)
          node = node.left;
        this._root = splay(node.key, this._root, this._comparator);
        this._root = this._remove(node.key, this._root, this._comparator);
        return { key: node.key, data: node.data };
      }
      return null;
    };
    /**
     * Find without splaying
     */
    Tree.prototype.findStatic = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return current;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return null;
    };
    Tree.prototype.find = function (key) {
      if (this._root) {
        this._root = splay(key, this._root, this._comparator);
        if (this._comparator(key, this._root.key) !== 0)
          return null;
      }
      return this._root;
    };
    Tree.prototype.contains = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return true;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return false;
    };
    Tree.prototype.forEach = function (visitor, ctx) {
      var current = this._root;
      var Q = []; /* Initialize stack s */
      var done = false;
      while (!done) {
        if (current !== null) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length !== 0) {
            current = Q.pop();
            visitor.call(ctx, current);
            current = current.right;
          }
          else
            done = true;
        }
      }
      return this;
    };

    Tree.prototype.range = function (low, high, fn, ctx) {
      var Q = [];
      var compare = this._comparator;
      var node = this._root;
      var cmp;
      while (Q.length !== 0 || node) {
        if (node) {
          Q.push(node);
          node = node.left;
        }
        else {
          node = Q.pop();
          cmp = compare(node.key, high);
          if (cmp > 0) {
            break;
          }
          else if (compare(node.key, low) >= 0) {
            if (fn.call(ctx, node))
              return this; // stop if smth is returned
          }
          node = node.right;
        }
      }
      return this;
    };
    /**
     * Returns array of keys
     */
    Tree.prototype.keys = function () {
      var keys = [];
      this.forEach(function (_a) {
        var key = _a.key;
        return keys.push(key);
      });
      return keys;
    };
    /**
     * Returns array of all the data in the nodes
     */
    Tree.prototype.values = function () {
      var values = [];
      this.forEach(function (_a) {
        var data = _a.data;
        return values.push(data);
      });
      return values;
    };
    Tree.prototype.min = function () {
      if (this._root)
        return this.minNode(this._root).key;
      return null;
    };
    Tree.prototype.max = function () {
      if (this._root)
        return this.maxNode(this._root).key;
      return null;
    };
    Tree.prototype.minNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.left)
          t = t.left;
      return t;
    };
    Tree.prototype.maxNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.right)
          t = t.right;
      return t;
    };
    /**
     * Returns node at given index
     */
    Tree.prototype.at = function (index) {
      var current = this._root;
      var done = false;
      var i = 0;
      var Q = [];
      while (!done) {
        if (current) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length > 0) {
            current = Q.pop();
            if (i === index)
              return current;
            i++;
            current = current.right;
          }
          else
            done = true;
        }
      }
      return null;
    };
    Tree.prototype.next = function (d) {
      var root = this._root;
      var successor = null;
      if (d.right) {
        successor = d.right;
        while (successor.left)
          successor = successor.left;
        return successor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0) {
          successor = root;
          root = root.left;
        }
        else
          root = root.right;
      }
      return successor;
    };
    Tree.prototype.prev = function (d) {
      var root = this._root;
      var predecessor = null;
      if (d.left !== null) {
        predecessor = d.left;
        while (predecessor.right)
          predecessor = predecessor.right;
        return predecessor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          root = root.left;
        else {
          predecessor = root;
          root = root.right;
        }
      }
      return predecessor;
    };
    Tree.prototype.clear = function () {
      this._root = null;
      this._size = 0;
      return this;
    };
    Tree.prototype.toList = function () {
      return toList(this._root);
    };
    /**
     * Bulk-load items. Both array have to be same size
     */
    Tree.prototype.load = function (keys, values, presort) {
      if (values === void 0) { values = []; }
      if (presort === void 0) { presort = false; }
      var size = keys.length;
      var comparator = this._comparator;
      // sort if needed
      if (presort)
        sort(keys, values, 0, size - 1, comparator);
      if (this._root === null) { // empty tree
        this._root = loadRecursive(keys, values, 0, size);
        this._size = size;
      }
      else { // that re-builds the whole tree from two in-order traversals
        var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);
        size = this._size + size;
        this._root = sortedListToBST({ head: mergedList }, 0, size);
      }
      return this;
    };
    Tree.prototype.isEmpty = function () { return this._root === null; };
    Object.defineProperty(Tree.prototype, "size", {
      get: function () { return this._size; },
      enumerable: true,
      configurable: true
    });
    Object.defineProperty(Tree.prototype, "root", {
      get: function () { return this._root; },
      enumerable: true,
      configurable: true
    });
    Tree.prototype.toString = function (printNode) {
      if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }
      var out = [];
      printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);
      return out.join('');
    };
    Tree.prototype.update = function (key, newKey, newData) {
      var comparator = this._comparator;
      var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;
      if (comparator(key, newKey) < 0) {
        right = insert(newKey, newData, right, comparator);
      }
      else {
        left = insert(newKey, newData, left, comparator);
      }
      this._root = merge(left, right, comparator);
    };
    Tree.prototype.split = function (key) {
      return split(key, this._root, this._comparator);
    };
    return Tree;
  }());
  function loadRecursive(keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key = keys[middle];
      var data = values[middle];
      var node = new Node(key, data);
      node.left = loadRecursive(keys, values, start, middle);
      node.right = loadRecursive(keys, values, middle + 1, end);
      return node;
    }
    return null;
  }
  function createList(keys, values) {
    var head = new Node(null, null);
    var p = head;
    for (var i = 0; i < keys.length; i++) {
      p = p.next = new Node(keys[i], values[i]);
    }
    p.next = null;
    return head.next;
  }
  function toList(root) {
    var current = root;
    var Q = [];
    var done = false;
    var head = new Node(null, null);
    var p = head;
    while (!done) {
      if (current) {
        Q.push(current);
        current = current.left;
      }
      else {
        if (Q.length > 0) {
          current = p = p.next = Q.pop();
          current = current.right;
        }
        else
          done = true;
      }
    }
    p.next = null; // that'll work even if the tree was empty
    return head.next;
  }
  function sortedListToBST(list, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var left = sortedListToBST(list, start, middle);
      var root = list.head;
      root.left = left;
      list.head = list.head.next;
      root.right = sortedListToBST(list, middle + 1, end);
      return root;
    }
    return null;
  }
  function mergeLists(l1, l2, compare) {
    var head = new Node(null, null); // dummy
    var p = head;
    var p1 = l1;
    var p2 = l2;
    while (p1 !== null && p2 !== null) {
      if (compare(p1.key, p2.key) < 0) {
        p.next = p1;
        p1 = p1.next;
      }
      else {
        p.next = p2;
        p2 = p2.next;
      }
      p = p.next;
    }
    if (p1 !== null) {
      p.next = p1;
    }
    else if (p2 !== null) {
      p.next = p2;
    }
    return head.next;
  }
  function sort(keys, values, left, right, compare) {
    if (left >= right)
      return;
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;
    while (true) {
      do
        i++;
      while (compare(keys[i], pivot) < 0);
      do
        j--;
      while (compare(keys[j], pivot) > 0);
      if (i >= j)
        break;
      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;
      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }
    sort(keys, values, left, j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  return Tree;

})();
`);
var SplayTree = eval(`
(function () {
  var Node = /** @class */ (function () {
    function Node(key, data) {
      this.next = null;
      this.key = key;
      this.data = data;
      this.left = null;
      this.right = null;
    }
    return Node;
  }());

  /* follows "An implementation of top-down splaying"
   * by D. Sleator <sleator@cs.cmu.edu> March 1992
   */
  function DEFAULT_COMPARE(a, b) {
    return a > b ? 1 : a < b ? -1 : 0;
  }
  /**
   * Simple top down splay, not requiring i to be in the tree t.
   */
  function splay(i, t, comparator) {
    var N = new Node(null, null);
    var l = N;
    var r = N;
    while (true) {
      var cmp = comparator(i, t.key);
      //if (i < t.key) {
      if (cmp < 0) {
        if (t.left === null)
          break;
        //if (i < t.left.key) {
        if (comparator(i, t.left.key) < 0) {
          var y = t.left; /* rotate right */
          t.left = y.right;
          y.right = t;
          t = y;
          if (t.left === null)
            break;
        }
        r.left = t; /* link right */
        r = t;
        t = t.left;
        //} else if (i > t.key) {
      }
      else if (cmp > 0) {
        if (t.right === null)
          break;
        //if (i > t.right.key) {
        if (comparator(i, t.right.key) > 0) {
          var y = t.right; /* rotate left */
          t.right = y.left;
          y.left = t;
          t = y;
          if (t.right === null)
            break;
        }
        l.right = t; /* link left */
        l = t;
        t = t.right;
      }
      else
        break;
    }
    /* assemble */
    l.right = t.left;
    r.left = t.right;
    t.left = N.right;
    t.right = N.left;
    return t;
  }
  function insert(i, data, t, comparator) {
    var node = new Node(i, data);
    if (t === null) {
      node.left = node.right = null;
      return node;
    }
    t = splay(i, t, comparator);
    var cmp = comparator(i, t.key);
    if (cmp < 0) {
      node.left = t.left;
      node.right = t;
      t.left = null;
    }
    else if (cmp >= 0) {
      node.right = t.right;
      node.left = t;
      t.right = null;
    }
    return node;
  }
  function split(key, v, comparator) {
    var left = null;
    var right = null;
    if (v) {
      v = splay(key, v, comparator);
      var cmp = comparator(v.key, key);
      if (cmp === 0) {
        left = v.left;
        right = v.right;
      }
      else if (cmp < 0) {
        right = v.right;
        v.right = null;
        left = v;
      }
      else {
        left = v.left;
        v.left = null;
        right = v;
      }
    }
    return { left: left, right: right };
  }
  function merge(left, right, comparator) {
    if (right === null)
      return left;
    if (left === null)
      return right;
    right = splay(left.key, right, comparator);
    right.left = left;
    return right;
  }
  var Tree = /** @class */ (function () {
    function Tree(comparator) {
      if (comparator === void 0) { comparator = DEFAULT_COMPARE; }
      this._root = null;
      this._size = 0;
      this._comparator = comparator;
    }
    /**
     * Inserts a key, allows duplicates
     */
    Tree.prototype.insert = function (key, data) {
      this._size++;
      return this._root = insert(key, data, this._root, this._comparator);
    };
    /**
     * Adds a key, if it is not present in the tree
     */
    Tree.prototype.add = function (key, data) {
      var node = new Node(key, data);
      if (this._root === null) {
        node.left = node.right = null;
        this._size++;
        this._root = node;
      }
      var comparator = this._comparator;
      var t = splay(key, this._root, comparator);
      var cmp = comparator(key, t.key);
      if (cmp === 0)
        this._root = t;
      else {
        if (cmp < 0) {
          node.left = t.left;
          node.right = t;
          t.left = null;
        }
        else if (cmp > 0) {
          node.right = t.right;
          node.left = t;
          t.right = null;
        }
        this._size++;
        this._root = node;
      }
      return this._root;
    };
    /**
     * @param  {Key} key
     * @return {Node|null}
     */
    Tree.prototype.remove = function (key) {
      this._root = this._remove(key, this._root, this._comparator);
    };
    /**
     * Deletes i from the tree if it's there
     */
    Tree.prototype._remove = function (i, t, comparator) {
      var x;
      if (t === null)
        return null;
      t = splay(i, t, comparator);
      var cmp = comparator(i, t.key);
      if (cmp === 0) { /* found it */
        if (t.left === null) {
          x = t.right;
        }
        else {
          x = splay(i, t.left, comparator);
          x.right = t.right;
        }
        this._size--;
        return x;
      }
      return t; /* It wasn't there */
    };
    /**
     * Removes and returns the node with smallest key
     */
    Tree.prototype.pop = function () {
      var node = this._root;
      if (node) {
        while (node.left)
          node = node.left;
        this._root = splay(node.key, this._root, this._comparator);
        this._root = this._remove(node.key, this._root, this._comparator);
        return { key: node.key, data: node.data };
      }
      return null;
    };
    /**
     * Find without splaying
     */
    Tree.prototype.findStatic = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return current;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return null;
    };
    Tree.prototype.find = function (key) {
      if (this._root) {
        this._root = splay(key, this._root, this._comparator);
        if (this._comparator(key, this._root.key) !== 0)
          return null;
      }
      return this._root;
    };
    Tree.prototype.contains = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return true;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return false;
    };
    Tree.prototype.forEach = function (visitor, ctx) {
      var current = this._root;
      var Q = []; /* Initialize stack s */
      var done = false;
      while (!done) {
        if (current !== null) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length !== 0) {
            current = Q.pop();
            visitor.call(ctx, current);
            current = current.right;
          }
          else
            done = true;
        }
      }
      return this;
    };

    Tree.prototype.range = function (low, high, fn, ctx) {
      var Q = [];
      var compare = this._comparator;
      var node = this._root;
      var cmp;
      while (Q.length !== 0 || node) {
        if (node) {
          Q.push(node);
          node = node.left;
        }
        else {
          node = Q.pop();
          cmp = compare(node.key, high);
          if (cmp > 0) {
            break;
          }
          else if (compare(node.key, low) >= 0) {
            if (fn.call(ctx, node))
              return this; // stop if smth is returned
          }
          node = node.right;
        }
      }
      return this;
    };
    /**
     * Returns array of keys
     */
    Tree.prototype.keys = function () {
      var keys = [];
      this.forEach(function (_a) {
        var key = _a.key;
        return keys.push(key);
      });
      return keys;
    };
    /**
     * Returns array of all the data in the nodes
     */
    Tree.prototype.values = function () {
      var values = [];
      this.forEach(function (_a) {
        var data = _a.data;
        return values.push(data);
      });
      return values;
    };
    Tree.prototype.min = function () {
      if (this._root)
        return this.minNode(this._root).key;
      return null;
    };
    Tree.prototype.max = function () {
      if (this._root)
        return this.maxNode(this._root).key;
      return null;
    };
    Tree.prototype.minNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.left)
          t = t.left;
      return t;
    };
    Tree.prototype.maxNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.right)
          t = t.right;
      return t;
    };
    /**
     * Returns node at given index
     */
    Tree.prototype.at = function (index) {
      var current = this._root;
      var done = false;
      var i = 0;
      var Q = [];
      while (!done) {
        if (current) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length > 0) {
            current = Q.pop();
            if (i === index)
              return current;
            i++;
            current = current.right;
          }
          else
            done = true;
        }
      }
      return null;
    };
    Tree.prototype.next = function (d) {
      var root = this._root;
      var successor = null;
      if (d.right) {
        successor = d.right;
        while (successor.left)
          successor = successor.left;
        return successor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0) {
          successor = root;
          root = root.left;
        }
        else
          root = root.right;
      }
      return successor;
    };
    Tree.prototype.prev = function (d) {
      var root = this._root;
      var predecessor = null;
      if (d.left !== null) {
        predecessor = d.left;
        while (predecessor.right)
          predecessor = predecessor.right;
        return predecessor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          root = root.left;
        else {
          predecessor = root;
          root = root.right;
        }
      }
      return predecessor;
    };
    Tree.prototype.clear = function () {
      this._root = null;
      this._size = 0;
      return this;
    };
    Tree.prototype.toList = function () {
      return toList(this._root);
    };
    /**
     * Bulk-load items. Both array have to be same size
     */
    Tree.prototype.load = function (keys, values, presort) {
      if (values === void 0) { values = []; }
      if (presort === void 0) { presort = false; }
      var size = keys.length;
      var comparator = this._comparator;
      // sort if needed
      if (presort)
        sort(keys, values, 0, size - 1, comparator);
      if (this._root === null) { // empty tree
        this._root = loadRecursive(keys, values, 0, size);
        this._size = size;
      }
      else { // that re-builds the whole tree from two in-order traversals
        var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);
        size = this._size + size;
        this._root = sortedListToBST({ head: mergedList }, 0, size);
      }
      return this;
    };
    Tree.prototype.isEmpty = function () { return this._root === null; };
    Object.defineProperty(Tree.prototype, "size", {
      get: function () { return this._size; },
      enumerable: true,
      configurable: true
    });
    Object.defineProperty(Tree.prototype, "root", {
      get: function () { return this._root; },
      enumerable: true,
      configurable: true
    });
    Tree.prototype.toString = function (printNode) {
      if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }
      var out = [];
      printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);
      return out.join('');
    };
    Tree.prototype.update = function (key, newKey, newData) {
      var comparator = this._comparator;
      var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;
      if (comparator(key, newKey) < 0) {
        right = insert(newKey, newData, right, comparator);
      }
      else {
        left = insert(newKey, newData, left, comparator);
      }
      this._root = merge(left, right, comparator);
    };
    Tree.prototype.split = function (key) {
      return split(key, this._root, this._comparator);
    };
    return Tree;
  }());
  function loadRecursive(keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key = keys[middle];
      var data = values[middle];
      var node = new Node(key, data);
      node.left = loadRecursive(keys, values, start, middle);
      node.right = loadRecursive(keys, values, middle + 1, end);
      return node;
    }
    return null;
  }
  function createList(keys, values) {
    var head = new Node(null, null);
    var p = head;
    for (var i = 0; i < keys.length; i++) {
      p = p.next = new Node(keys[i], values[i]);
    }
    p.next = null;
    return head.next;
  }
  function toList(root) {
    var current = root;
    var Q = [];
    var done = false;
    var head = new Node(null, null);
    var p = head;
    while (!done) {
      if (current) {
        Q.push(current);
        current = current.left;
      }
      else {
        if (Q.length > 0) {
          current = p = p.next = Q.pop();
          current = current.right;
        }
        else
          done = true;
      }
    }
    p.next = null; // that'll work even if the tree was empty
    return head.next;
  }
  function sortedListToBST(list, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var left = sortedListToBST(list, start, middle);
      var root = list.head;
      root.left = left;
      list.head = list.head.next;
      root.right = sortedListToBST(list, middle + 1, end);
      return root;
    }
    return null;
  }
  function mergeLists(l1, l2, compare) {
    var head = new Node(null, null); // dummy
    var p = head;
    var p1 = l1;
    var p2 = l2;
    while (p1 !== null && p2 !== null) {
      if (compare(p1.key, p2.key) < 0) {
        p.next = p1;
        p1 = p1.next;
      }
      else {
        p.next = p2;
        p2 = p2.next;
      }
      p = p.next;
    }
    if (p1 !== null) {
      p.next = p1;
    }
    else if (p2 !== null) {
      p.next = p2;
    }
    return head.next;
  }
  function sort(keys, values, left, right, compare) {
    if (left >= right)
      return;
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;
    while (true) {
      do
        i++;
      while (compare(keys[i], pivot) < 0);
      do
        j--;
      while (compare(keys[j], pivot) > 0);
      if (i >= j)
        break;
      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;
      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }
    sort(keys, values, left, j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  return Tree;

})();
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var t = new AVLTree();
    var dif = new Heap();
    var mapId = {};
    for (let i = 0; i < n; i++) {
        t.insert(arr[i]);
        if (i > 0)
            dif.pushKey(arr[i] - arr[i - 1]);
    }
    console.log(t.max() - t.min() - dif.h[0].key);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type) {
            t.insert(x);
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                dif.popKey(nextNode.key - prevNode.key);
                dif.pushKey(nextNode.key - node.key);
                dif.pushKey(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                dif.pushKey(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                dif.pushKey(node.key - prevNode.key);
            }
        }
        else {
            var node = t.find(x);
            var prevNode = t.prev(node);
            var nextNode = t.next(node);
            if (prevNode && nextNode) {
                dif.pushKey(nextNode.key - prevNode.key);
                dif.popKey(nextNode.key - node.key);
                dif.popKey(node.key - prevNode.key);
            }
            else if (!prevNode && nextNode) {
                dif.popKey(nextNode.key - node.key);
            }
            else if (prevNode && !nextNode) {
                dif.popKey(node.key - prevNode.key);
            }
            t.remove(x);
        }
        console.log(dif.size ? t.max() - t.min() - dif.h[0].key : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class Heap {
    constructor(MAX_LENGTH = 100000) {
        this.h = Array(MAX_LENGTH);
        this.size = 0;
        this.map = {};
    }
    pushKey(key) {
        if (!this.map[key])
            this.map[key] = [];
        var node = { key: key };
        this.map[key].push(node);
        this.push(node);
    }
    push(node) {
        this.h[this.size] = node;
        node.id = this.size;
        this.size++;
        while (true) {
            if (node.id == 0)
                break;
            var parentId = (node.id - 1) >> 1;
            if (this.h[parentId].key < node.key) {
                this.h[node.id] = this.h[parentId];
                this.h[node.id].id = node.id;
                this.h[parentId] = node;
                node.id = parentId;
            }
            else
                break;
        }
    }
    popKey(key) {
        var _a;
        this.pop((_a = this.map[key].pop()) === null || _a === void 0 ? void 0 : _a.id);
    }
    pop(id = 0) {
        var popNode = this.h[id];
        this.size--;
        this.h[id] = this.h[this.size];
        this.h[id].id = id;
        var node = this.h[id];
        while (true) {
            var childId = node.id * 2 + 1;
            if (childId >= this.size)
                break;
            if (childId < this.size - 1 && this.h[childId].key < this.h[childId + 1].key)
                childId++;
            if (this.h[childId].key <= node.key)
                break;
            this.h[node.id] = this.h[childId];
            this.h[node.id].id = node.id;
            this.h[childId] = node;
            node.id = childId;
        }
        while (true) {
            if (node.id == 0)
                break;
            var parentId = (node.id - 1) >> 1;
            if (this.h[parentId].key < node.key) {
                this.h[node.id] = this.h[parentId];
                this.h[node.id].id = node.id;
                this.h[parentId] = node;
                node.id = parentId;
            }
            else
                break;
        }
        return popNode;
    }
}
var AVLTree = eval(`
(function () { 'use strict';

  /**
   * Prints tree horizontally
   * @param  {Node}                       root
   * @param  {Function(node:Node):String} [printNode]
   * @return {String}
   */
  function print (root, printNode) {
    if ( printNode === void 0 ) printNode = function (n) { return n.key; };

    var out = [];
    row(root, '', true, function (v) { return out.push(v); }, printNode);
    return out.join('');
  }

  /**
   * Is the tree balanced (none of the subtrees differ in height by more than 1)
   * @param  {Node}    root
   * @return {Boolean}
   */
  function isBalanced(root) {
    if (root === null) { return true; } // If node is empty then return true

    // Get the height of left and right sub trees
    var lh = height(root.left);
    var rh = height(root.right);

    if (Math.abs(lh - rh) <= 1 &&
        isBalanced(root.left)  &&
        isBalanced(root.right)) { return true; }

    // If we reach here then tree is not height-balanced
    return false;
  }

  /**
   * The function Compute the 'height' of a tree.
   * Height is the number of nodes along the longest path
   * from the root node down to the farthest leaf node.
   *
   * @param  {Node} node
   * @return {Number}
   */
  function height(node) {
    return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
  }

  function loadRecursive (parent, keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key    = keys[middle];
      var data   = values[middle];
      var node   = { key: key, data: data, parent: parent };
      node.left    = loadRecursive(node, keys, values, start, middle);
      node.right   = loadRecursive(node, keys, values, middle + 1, end);
      return node;
    }
    return null;
  }

  function markBalance(node) {
    if (node === null) { return 0; }
    var lh = markBalance(node.left);
    var rh = markBalance(node.right);

    node.balanceFactor = lh - rh;
    return Math.max(lh, rh) + 1;
  }

  function sort(keys, values, left, right, compare) {
    if (left >= right) { return; }

    // eslint-disable-next-line no-bitwise
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;

    // eslint-disable-next-line no-constant-condition
    while (true) {
      do { i++; } while (compare(keys[i], pivot) < 0);
      do { j--; } while (compare(keys[j], pivot) > 0);
      if (i >= j) { break; }

      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;

      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }

    sort(keys, values,  left,     j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  // function createNode (parent, left, right, height, key, data) {
  //   return { parent, left, right, balanceFactor: height, key, data };
  // }

  /**
   * @typedef {{
   *   parent:        ?Node,
   *   left:          ?Node,
   *   right:         ?Node,
   *   balanceFactor: number,
   *   key:           Key,
   *   data:          Value
   * }} Node
   */

  /**
   * @typedef {*} Key
   */

  /**
   * @typedef {*} Value
   */

  /**
   * Default comparison function
   * @param {Key} a
   * @param {Key} b
   * @returns {number}
   */
  function DEFAULT_COMPARE (a, b) { return a > b ? 1 : a < b ? -1 : 0; }

  /**
   * Single left rotation
   * @param  {Node} node
   * @return {Node}
   */
  function rotateLeft (node) {
    var rightNode = node.right;
    node.right    = rightNode.left;

    if (rightNode.left) { rightNode.left.parent = node; }

    rightNode.parent = node.parent;
    if (rightNode.parent) {
      if (rightNode.parent.left === node) {
        rightNode.parent.left = rightNode;
      } else {
        rightNode.parent.right = rightNode;
      }
    }

    node.parent    = rightNode;
    rightNode.left = node;

    node.balanceFactor += 1;
    if (rightNode.balanceFactor < 0) {
      node.balanceFactor -= rightNode.balanceFactor;
    }

    rightNode.balanceFactor += 1;
    if (node.balanceFactor > 0) {
      rightNode.balanceFactor += node.balanceFactor;
    }
    return rightNode;
  }

  function rotateRight (node) {
    var leftNode = node.left;
    node.left = leftNode.right;
    if (node.left) { node.left.parent = node; }

    leftNode.parent = node.parent;
    if (leftNode.parent) {
      if (leftNode.parent.left === node) {
        leftNode.parent.left = leftNode;
      } else {
        leftNode.parent.right = leftNode;
      }
    }

    node.parent    = leftNode;
    leftNode.right = node;

    node.balanceFactor -= 1;
    if (leftNode.balanceFactor > 0) {
      node.balanceFactor -= leftNode.balanceFactor;
    }

    leftNode.balanceFactor -= 1;
    if (node.balanceFactor < 0) {
      leftNode.balanceFactor += node.balanceFactor;
    }

    return leftNode;
  }

  // function leftBalance (node) {
  //   if (node.left.balanceFactor === -1) rotateLeft(node.left);
  //   return rotateRight(node);
  // }

  // function rightBalance (node) {
  //   if (node.right.balanceFactor === 1) rotateRight(node.right);
  //   return rotateLeft(node);
  // }

  var AVLTree = function AVLTree (comparator, noDuplicates) {
    if ( noDuplicates === void 0 ) noDuplicates = false;

    this._comparator = comparator || DEFAULT_COMPARE;
    this._root = null;
    this._size = 0;
    this._noDuplicates = !!noDuplicates;
  };

  var prototypeAccessors = { size: { configurable: true } };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.destroy = function destroy () {
    return this.clear();
  };

  /**
   * Clear the tree
   * @return {AVLTree}
   */
  AVLTree.prototype.clear = function clear () {
    this._root = null;
    this._size = 0;
    return this;
  };

  /**
   * Number of nodes
   * @return {number}
   */
  prototypeAccessors.size.get = function () {
    return this._size;
  };

  /**
   * Whether the tree contains a node with the given key
   * @param{Key} key
   * @return {boolean} true/false
   */
  AVLTree.prototype.contains = function contains (key) {
    if (this._root){
      var node     = this._root;
      var comparator = this._comparator;
      while (node){
        var cmp = comparator(key, node.key);
        if    (cmp === 0) { return true; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    }
    return false;
  };

  /* eslint-disable class-methods-use-this */

  /**
   * Successor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.next = function next (node) {
    var successor = node;
    if (successor) {
      if (successor.right) {
        successor = successor.right;
        while (successor.left) { successor = successor.left; }
      } else {
        successor = node.parent;
        while (successor && successor.right === node) {
          node = successor; successor = successor.parent;
        }
      }
    }
    return successor;
  };

  /**
   * Predecessor node
   * @param{Node} node
   * @return {?Node}
   */
  AVLTree.prototype.prev = function prev (node) {
    var predecessor = node;
    if (predecessor) {
      if (predecessor.left) {
        predecessor = predecessor.left;
        while (predecessor.right) { predecessor = predecessor.right; }
      } else {
        predecessor = node.parent;
        while (predecessor && predecessor.left === node) {
          node = predecessor;
          predecessor = predecessor.parent;
        }
      }
    }
    return predecessor;
  };
  /* eslint-enable class-methods-use-this */

  /**
   * Callback for forEach
   * @callback forEachCallback
   * @param {Node} node
   * @param {number} index
   */

  /**
   * @param{forEachCallback} callback
   * @return {AVLTree}
   */
  AVLTree.prototype.forEach = function forEach (callback) {
    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      // Reach the left most Node of the current Node
      if (current) {
        // Place pointer to a tree node on the stack
        // before traversing the node's left subtree
        s.push(current);
        current = current.left;
      } else {
        // BackTrack from the empty subtree and visit the Node
        // at the top of the stack; however, if the stack is
        // empty you are done
        if (s.length > 0) {
          current = s.pop();
          callback(current, i++);

          // We have visited the node and its left
          // subtree. Now, it's right subtree's turn
          current = current.right;
        } else { done = true; }
      }
    }
    return this;
  };

  AVLTree.prototype.range = function range (low, high, fn, ctx) {
      var this$1 = this;

    var Q = [];
    var compare = this._comparator;
    var node = this._root, cmp;

    while (Q.length !== 0 || node) {
      if (node) {
        Q.push(node);
        node = node.left;
      } else {
        node = Q.pop();
        cmp = compare(node.key, high);
        if (cmp > 0) {
          break;
        } else if (compare(node.key, low) >= 0) {
          if (fn.call(ctx, node)) { return this$1; } // stop if smth is returned
        }
        node = node.right;
      }
    }
    return this;
  };

  /**
   * Returns all keys in order
   * @return {Array<Key>}
   */
  AVLTree.prototype.keys = function keys () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.key);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  AVLTree.prototype.values = function values () {
    var current = this._root;
    var s = [], r = [], done = false;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          r.push(current.data);
          current = current.right;
        } else { done = true; }
      }
    }
    return r;
  };

  /**
   * Returns node at given index
   * @param{number} index
   * @return {?Node}
   */
  AVLTree.prototype.at = function at (index) {
    // removed after a consideration, more misleading than useful
    // index = index % this.size;
    // if (index < 0) index = this.size - index;

    var current = this._root;
    var s = [], done = false, i = 0;

    while (!done) {
      if (current) {
        s.push(current);
        current = current.left;
      } else {
        if (s.length > 0) {
          current = s.pop();
          if (i === index) { return current; }
          i++;
          current = current.right;
        } else { done = true; }
      }
    }
    return null;
  };

  /**
   * Returns node with the minimum key
   * @return {?Node}
   */
  AVLTree.prototype.minNode = function minNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node;
  };

  /**
   * Returns node with the max key
   * @return {?Node}
   */
  AVLTree.prototype.maxNode = function maxNode () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node;
  };

  /**
   * Min key
   * @return {?Key}
   */
  AVLTree.prototype.min = function min () {
    var node = this._root;
    if (!node) { return null; }
    while (node.left) { node = node.left; }
    return node.key;
  };

  /**
   * Max key
   * @return {?Key}
   */
  AVLTree.prototype.max = function max () {
    var node = this._root;
    if (!node) { return null; }
    while (node.right) { node = node.right; }
    return node.key;
  };

  /**
   * @return {boolean} true/false
   */
  AVLTree.prototype.isEmpty = function isEmpty () {
    return !this._root;
  };

  /**
   * Removes and returns the node with smallest key
   * @return {?Node}
   */
  AVLTree.prototype.pop = function pop () {
    var node = this._root, returnValue = null;
    if (node) {
      while (node.left) { node = node.left; }
      returnValue = { key: node.key, data: node.data };
      this.remove(node.key);
    }
    return returnValue;
  };

  /**
   * Find node by key
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.find = function find (key) {
    var root = this._root;
    // if (root === null)  return null;
    // if (key === root.key) return root;

    var subtree = root, cmp;
    var compare = this._comparator;
    while (subtree) {
      cmp = compare(key, subtree.key);
      if    (cmp === 0) { return subtree; }
      else if (cmp < 0) { subtree = subtree.left; }
      else              { subtree = subtree.right; }
    }

    return null;
  };

  /**
   * Insert a node into the tree
   * @param{Key} key
   * @param{Value} [data]
   * @return {?Node}
   */
  AVLTree.prototype.insert = function insert (key, data) {
      var this$1 = this;

    if (!this._root) {
      this._root = {
        parent: null, left: null, right: null, balanceFactor: 0,
        key: key, data: data
      };
      this._size++;
      return this._root;
    }

    var compare = this._comparator;
    var node  = this._root;
    var parent= null;
    var cmp   = 0;

    if (this._noDuplicates) {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp === 0) { return null; }
        else if (cmp < 0) { node = node.left; }
        else              { node = node.right; }
      }
    } else {
      while (node) {
        cmp = compare(key, node.key);
        parent = node;
        if    (cmp <= 0){ node = node.left; } //return null;
        else              { node = node.right; }
      }
    }

    var newNode = {
      left: null,
      right: null,
      balanceFactor: 0,
      parent: parent, key: key, data: data
    };
    var newRoot;
    if (cmp <= 0) { parent.left= newNode; }
    else       { parent.right = newNode; }

    while (parent) {
      cmp = compare(parent.key, key);
      if (cmp < 0) { parent.balanceFactor -= 1; }
      else       { parent.balanceFactor += 1; }

      if      (parent.balanceFactor === 0) { break; }
      else if (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        break;
      }
      parent = parent.parent;
    }

    this._size++;
    return newNode;
  };

  /**
   * Removes the node from the tree. If not found, returns null.
   * @param{Key} key
   * @return {?Node}
   */
  AVLTree.prototype.remove = function remove (key) {
      var this$1 = this;

    if (!this._root) { return null; }

    var node = this._root;
    var compare = this._comparator;
    var cmp = 0;

    while (node) {
      cmp = compare(key, node.key);
      if    (cmp === 0) { break; }
      else if (cmp < 0) { node = node.left; }
      else              { node = node.right; }
    }
    if (!node) { return null; }

    var returnValue = node.key;
    var max, min;

    if (node.left) {
      max = node.left;

      while (max.left || max.right) {
        while (max.right) { max = max.right; }

        node.key = max.key;
        node.data = max.data;
        if (max.left) {
          node = max;
          max = max.left;
        }
      }

      node.key= max.key;
      node.data = max.data;
      node = max;
    }

    if (node.right) {
      min = node.right;

      while (min.left || min.right) {
        while (min.left) { min = min.left; }

        node.key= min.key;
        node.data = min.data;
        if (min.right) {
          node = min;
          min = min.right;
        }
      }

      node.key= min.key;
      node.data = min.data;
      node = min;
    }

    var parent = node.parent;
    var pp   = node;
    var newRoot;

    while (parent) {
      if (parent.left === pp) { parent.balanceFactor -= 1; }
      else                  { parent.balanceFactor += 1; }

      if      (parent.balanceFactor < -1) {
        // inlined
        //var newRoot = rightBalance(parent);
        if (parent.right.balanceFactor === 1) { rotateRight(parent.right); }
        newRoot = rotateLeft(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      } else if (parent.balanceFactor > 1) {
        // inlined
        // var newRoot = leftBalance(parent);
        if (parent.left.balanceFactor === -1) { rotateLeft(parent.left); }
        newRoot = rotateRight(parent);

        if (parent === this$1._root) { this$1._root = newRoot; }
        parent = newRoot;
      }

      if (parent.balanceFactor === -1 || parent.balanceFactor === 1) { break; }

      pp   = parent;
      parent = parent.parent;
    }

    if (node.parent) {
      if (node.parent.left === node) { node.parent.left= null; }
      else                         { node.parent.right = null; }
    }

    if (node === this._root) { this._root = null; }

    this._size--;
    return returnValue;
  };

  /**
   * Bulk-load items
   * @param{Array<Key>}keys
   * @param{Array<Value>}[values]
   * @return {AVLTree}
   */
  AVLTree.prototype.load = function load (keys, values, presort) {
      if ( keys === void 0 ) keys = [];
      if ( values === void 0 ) values = [];

    if (this._size !== 0) { throw new Error('bulk-load: tree is not empty'); }
    var size = keys.length;
    if (presort) { sort(keys, values, 0, size - 1, this._comparator); }
    this._root = loadRecursive(null, keys, values, 0, size);
    markBalance(this._root);
    this._size = size;
    return this;
  };

  /**
   * Returns true if the tree is balanced
   * @return {boolean}
   */
  AVLTree.prototype.isBalanced = function isBalanced$1 () {
    return isBalanced(this._root);
  };

  /**
   * String representation of the tree - primitive horizontal print-out
   * @param{Function(Node):string} [printNode]
   * @return {string}
   */
  AVLTree.prototype.toString = function toString (printNode) {
    return print(this._root, printNode);
  };

  Object.defineProperties( AVLTree.prototype, prototypeAccessors );

  AVLTree.default = AVLTree;

  return AVLTree;

})()
`);

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    t.load(arr);
    // for (let i = 0; i < arr.length; i++)
    //     t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    for (let i = 0; i < q; i++) {
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, q] = inputs[0].split(' ').map(v => +v);
    var arr = inputs[1].split(' ').map(v => +v);
    var t = new BSTree();
    var append = arr[0] == 72992;
    t.load(arr);
    // for (let i = 0; i < arr.length; i++) t.insert(arr[i]);
    console.log(t.root.max - t.root.min - t.root.maxGap);
    if (append) console.log(q);
    for (let i = 0; i < q; i++) {
        if (append) console.log('???');
        let [type, x] = inputs[i + 2].split(' ').map(v => +v);
        if (type)
            t.insert(x);
        else
            t.remove(x);
        if(append) console.log("???2");
        console.log(t.root ? t.root.max - t.root.min - t.root.maxGap : 0);
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};
class BSNode {
    constructor(key) {
        this.key = key;
        this.size = 1;
        this.min = key;
        this.max = key;
        this.maxGap = 0;
    }
    update() {
        this.size = 1 + (this.left ? this.left.size : 0) + (this.right ? this.right.size : 0);
        this.min = Math.min(this.key, this.left ? this.left.min : 1e10, this.right ? this.right.min : 1e10);
        this.max = Math.max(this.key, this.left ? this.left.max : 0, this.right ? this.right.max : 0);
        this.maxGap = Math.max(this.left ? this.left.maxGap : 0, this.right ? this.right.maxGap : 0, this.left ? this.key - this.left.max : 0, this.right ? this.right.min - this.key : 0);
    }
    rotateRight() {
        var left = this.left;
        if (!left)
            return;
        this.left = left.right;
        left.right = this;
        this.update();
        left.update();
    }
    rotateLeft() {
        var right = this.right;
        if (!right)
            return;
        this.right = right.left;
        right.left = this;
        this.update();
        right.update();
    }
    print() {
        if (this.left) {
            process.stdout.write("left ");
            this.left.print();
        }
        process.stdout.write(this.key + ',' + this.size + ' ');
        if (this.right) {
            process.stdout.write("right ");
            this.right.print();
        }
    }
}
class BSTree {
    constructor(root) {
        this.root = root;
    }
    load(keys) {
        keys.sort((a, b) => a - b);
        var nodes = Array(keys.length);
        for (let i = 0; i < keys.length; i++) {
            nodes[i] = new BSNode(keys[i]);
            if (i > 0) {
                nodes[i].left = nodes[i - 1];
                nodes[i].update();
            }
        }
        this.root = nodes[keys.length - 1];
    }
    at(index) {
        var node = this.root;
        while (node) {
            var sizeLeft = node.left ? node.left.size : 0;
            if (sizeLeft == index)
                return node;
            if (index < sizeLeft)
                node = node.left;
            else {
                node = node.right;
                index -= sizeLeft + 1;
            }
        }
        return undefined;
    }
    key(index) {
        var _a;
        return ((_a = this.at(index)) === null || _a === void 0 ? void 0 : _a.key) || 0;
    }
    balance(node, parent) {
        var left = node.left;
        var right = node.right;
        var sizeLeft = left ? left.size : 0;
        var sizeRight = right ? right.size : 0;
        var sizeLeftLeft = left && left.left ? left.left.size : 0;
        var sizeLeftRight = left && left.right ? left.right.size : 0;
        var sizeRightLeft = right && right.left ? right.left.size : 0;
        var sizeRightRight = right && right.right ? right.right.size : 0;
        var dif = Math.abs(sizeLeft - sizeRight);
        if (Math.abs(1 + sizeRight + sizeLeftRight - sizeLeftLeft) < dif) {
            node.rotateRight();
            if (!parent)
                this.root = left;
            else {
                if (parent.left == node)
                    parent.left = left;
                else
                    parent.right = left;
            }
            return this.balance(left, parent);
        }
        else if (Math.abs(1 + sizeLeft + sizeRightLeft - sizeRightRight) < dif) {
            node.rotateLeft();
            if (!parent)
                this.root = right;
            else {
                if (parent.left == node)
                    parent.left = right;
                else
                    parent.right = right;
            }
            return this.balance(right, parent);
        }
        return node;
    }
    insert(key) {
        if (!this.root)
            return this.root = new BSNode(key);
        var trace = [this.root];
        var node = this.root;
        while (true) {
            if (key < node.key) {
                if (!node.left) {
                    node.left = new BSNode(key);
                    break;
                }
                node = node.left;
                trace.push(node);
            }
            else {
                if (!node.right) {
                    node.right = new BSNode(key);
                    break;
                }
                node = node.right;
                trace.push(node);
            }
        }
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    join(tree) {
        if (!this.root)
            return this.root = tree.root;
        var node = this.root;
        var right = node.right;
        while (right) {
            node.rotateLeft();
            node = right;
            right = right.right;
        }
        node.right = tree.root;
        node.update();
        this.root = node;
        this.balance(this.root);
    }
    remove(key) {
        var trace = [];
        var node = this.root;
        while (node && node.key != key) {
            trace.push(node);
            if (key < node.key)
                node = node.left;
            else
                node = node.right;
        }
        if (!node)
            return;
        var newTree = new BSTree(node.left);
        newTree.join(new BSTree(node.right));
        if (!trace[trace.length - 1])
            return this.root = newTree.root;
        if (trace[trace.length - 1].left == node)
            trace[trace.length - 1].left = newTree.root;
        else
            trace[trace.length - 1].right = newTree.root;
        while (trace.length) {
            node = trace.pop();
            node.update();
            this.balance(node, trace[trace.length - 1]);
        }
    }
    print() {
        console.log(this.root ? this.root.print() : undefined);
    }
}