I won't feel lonely, nor will I be sorrowful... not before everything is buried.

A string of n beads is left as the message of leaving. The beads are numbered from 1 to n from left to right, each having a shape numbered by integers between 1 and n inclusive. Some beads may have the same shapes.

The memory of a shape x in a certain subsegment of beads, is defined to be the difference between the last position and the first position that shape x appears in the segment. The memory of a subsegment is the sum of memories over all shapes that occur in it.

From time to time, shapes of beads change as well as the memories. Sometimes, the past secreted in subsegments are being recalled, and you are to find the memory for each of them.

Input

The first line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 100 000) — the number of beads in the string, and the total number of changes and queries, respectively.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ n) — the initial shapes of beads 1, 2, ..., n, respectively.

The following m lines each describes either a change in the beads or a query of subsegment. A line has one of the following formats: 

  * 1 p x (1 ≤ p ≤ n, 1 ≤ x ≤ n), meaning that the shape of the p-th bead is changed into x; 
  * 2 l r (1 ≤ l ≤ r ≤ n), denoting a query of memory of the subsegment from l to r, inclusive. 

Output

For each query, print one line with an integer — the memory of the recalled subsegment.

Examples

Input

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


Output

5
0
7
1


Input

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


Output

0
0

Note

The initial string of beads has shapes (1, 2, 3, 1, 3, 2, 1).

Consider the changes and queries in their order: 

  1. 2 3 7: the memory of the subsegment [3, 7] is (7 - 4) + (6 - 6) + (5 - 3) = 5; 
  2. 2 1 3: the memory of the subsegment [1, 3] is (1 - 1) + (2 - 2) + (3 - 3) = 0; 
  3. 1 7 2: the shape of the 7-th bead changes into 2. Beads now have shapes (1, 2, 3, 1, 3, 2, 2) respectively; 
  4. 1 3 2: the shape of the 3-rd bead changes into 2. Beads now have shapes (1, 2, 2, 1, 3, 2, 2) respectively; 
  5. 2 1 6: the memory of the subsegment [1, 6] is (4 - 1) + (6 - 2) + (5 - 5) = 7; 
  6. 2 5 7: the memory of the subsegment [5, 7] is (7 - 6) + (5 - 5) = 1. 
#include <bits/stdc++.h>
using namespace std;
struct fenwick_tree_1D {
  long long n, log_n;
  vector<long long> tree;
  fenwick_tree_1D(long long _n)
      : n(_n), log_n((long long)(log2(_n) + 1.0L)), tree(_n + 5) {}
  void update(long long x, long long v) {
    while (x <= n) {
      tree[x] += v;
      x += x & (-x);
    }
  }
  long long prefix_sum(long long x) {
    long long r = 0;
    while (x) {
      r += tree[x];
      x -= x & (-x);
    }
    return r;
  }
  long long range_sum(long long l, long long r) {
    return prefix_sum(r) - prefix_sum(l - 1);
  }
};
const long long bs = 300;
fenwick_tree_1D bit(100005);
long long a[100005], nxt[100005], last[100005] = {0}, dl[2 * bs + 5],
                                  id[100005], dc = 0, result[100005] = {0};
set<long long> s[100005];
long long qc;
struct query {
  long long t, l, r, qno;
} q[bs + 5];
long long q2c;
struct query2 {
  long long l, r, qno;
} q2[bs + 5];
vector<long long> ans;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    s[a[i]].insert(i);
  }
  for (long long h = 0; h < m; h += bs) {
    qc = min(bs, m - h);
    for (long long j = 0; j < qc; j++) {
      cin >> q[j].t >> q[j].l >> q[j].r;
      q[j].qno = h + j;
      if (q[j].t == 1) {
        if (!id[a[q[j].l]]) dl[dc] = a[q[j].l], id[a[q[j].l]] = 1, dc++;
        if (!id[q[j].r]) dl[dc] = q[j].r, id[q[j].r] = 1, dc++;
      } else
        q2[q2c].l = q[j].l, q2[q2c].r = q[j].r, q2[q2c].qno = q[j].qno,
        ans.push_back(q[j].qno), q2c++;
    }
    for (long long i = n; i >= 1; i--) {
      if (id[a[i]]) {
        nxt[i] = 0;
        continue;
      }
      nxt[i] = last[a[i]];
      if (nxt[i]) bit.update(nxt[i], nxt[i] - i);
      last[a[i]] = i;
    }
    sort(q2, q2 + q2c,
         [](const query2 &l, const query2 &r) { return l.l < r.l; });
    long long pos = 1;
    for (long long i = 0; i < q2c; i++) {
      while (pos < q2[i].l) {
        if (id[a[pos]] || !nxt[pos]) {
          pos++;
          continue;
        }
        bit.update(nxt[pos], pos - nxt[pos]);
        pos++;
      }
      result[q2[i].qno] = bit.prefix_sum(q2[i].r);
    }
    for (long long i = 0; i < qc; i++) {
      if (q[i].t == 1) {
        s[a[q[i].l]].erase(q[i].l);
        a[q[i].l] = q[i].r;
        s[a[q[i].l]].insert(q[i].l);
      } else {
        for (long long j = 0; j < dc; j++) {
          auto it1 = s[dl[j]].lower_bound(q[i].l);
          auto it2 = s[dl[j]].upper_bound(q[i].r);
          if (it1 != s[dl[j]].end() && it2 != s[dl[j]].begin()) {
            it2--;
            if (*it2 > *it1) result[q[i].qno] += *it2 - *it1;
          }
        }
      }
    }
    for (long long i = 0; i < dc; i++) id[dl[i]] = 0;
    dc = 0;
    q2c = 0;
    for (long long i = 1; i <= n; i++) bit.tree[i] = 0, last[i] = 0;
  }
  for (auto &k : ans) cout << result[k] << "\n";
}
