#include <bits/stdc++.h>
using namespace std;
const int N = 100010, B = 2200, S = 320;
map<int, int> hm;
int n, m, cnt;
int a[N];
int m1, m2;
struct Node {
  int l, r, t, lb, rb, idx;
  bool operator<(const Node &a) const {
    return (lb != a.lb) ? (lb < a.lb)
                        : ((rb != a.rb) ? (rb < a.rb) : (t < a.t));
  }
} b[N];
int p[N], x[N];
int d[N], zc[S], c[N * 2];
inline void D_Add(int x) {
  if (!d[x]++) --zc[x / S];
  return;
}
inline void D_Dec(int x) {
  if (!--d[x]) ++zc[x / S];
  return;
}
inline void Add(int x) {
  D_Dec(c[x]);
  D_Add(++c[x]);
  return;
}
inline void Dec(int x) {
  D_Dec(c[x]);
  D_Add(--c[x]);
  return;
}
inline void Transform(int l, int r, int t) {
  if (l <= p[t] && p[t] <= r) {
    Dec(a[p[t]]);
    Add(x[t]);
  }
  swap(a[p[t]], x[t]);
  return;
}
inline int Query() {
  for (int i = 0; i <= cnt; i += S)
    if (zc[i / S]) {
      for (int j = 0; j < S; ++j)
        if (!d[i + j]) return i + j;
    }
  return -1;
}
int res[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    hm[a[i]] = 0;
  }
  for (int i = 1; i <= m; ++i) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      ++m1;
      scanf("%d%d", &b[m1].l, &b[m1].r);
      b[m1].lb = b[m1].l / B;
      b[m1].rb = b[m1].r / B;
      b[m1].t = m2;
      b[m1].idx = m1;
    } else {
      ++m2;
      scanf("%d%d", &p[m2], &x[m2]);
      hm[x[m2]] = 0;
    }
  }
  cnt = 0;
  for (map<int, int>::iterator i = hm.begin(); i != hm.end(); ++i)
    i->second = ++cnt;
  for (int i = 1; i <= n; ++i) a[i] = hm[a[i]];
  for (int i = 1; i <= m2; ++i)
    if (x[i]) x[i] = hm[x[i]];
  sort(b + 1, b + m1 + 1);
  d[0] = cnt + 1;
  for (int i = 1; i <= n; ++i) ++zc[i / S];
  int l = 1, r = 0, t = 0;
  for (int i = 1; i <= m1; ++i) {
    while (b[i].l < l) Add(a[--l]);
    while (r < b[i].r) Add(a[++r]);
    while (l < b[i].l) Dec(a[l++]);
    while (b[i].r < r) Dec(a[r--]);
    while (t < b[i].t) Transform(l, r, ++t);
    while (b[i].t < t) Transform(l, r, t--);
    res[b[i].idx] = Query();
  }
  for (int i = 1; i <= m1; ++i) printf("%d\n", res[i]);
  return 0;
}
