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;
template <typename T>
struct node {
  node<T>*left, *right;
  T value;
  node<T>() {
    left = right = NULL;
    value = T(0);
  }
};
template <typename T>
struct tree {
  using bound_t = int;
  const bound_t left_bound = 0;
  const bound_t right_bound = 100100;
  using tnode = node<T>;
  tnode* root;
  tree<T>() { root = NULL; }
  tnode* update(tnode* cur, bound_t l, bound_t r, bound_t pos, T v) {
    if (cur == NULL) cur = new tnode();
    if (l == r)
      cur->value = cur->value + v;
    else {
      bound_t mid = (l + r) >> 1;
      if (pos <= mid)
        cur->left = update(cur->left, l, mid, pos, v);
      else
        cur->right = update(cur->right, mid + 1, r, pos, v);
      cur->value = (cur->left ? cur->left->value : T(0)) +
                   (cur->right ? cur->right->value : T(0));
    }
    return cur;
  }
  void update(bound_t pos, T v) {
    root = update(root, left_bound, right_bound, pos, v);
  }
  T query(tnode* cur, bound_t l, bound_t r, bound_t x, bound_t y) {
    if (cur == NULL || l > y || r < x) return T(0);
    if (x <= l && r <= y) return cur->value;
    bound_t mid = (l + r) >> 1;
    T le = query(cur->left, l, mid, x, y);
    T ri = query(cur->right, mid + 1, r, x, y);
    return le + ri;
  }
  T query(bound_t x, bound_t y) {
    return query(root, left_bound, right_bound, x, y);
  }
};
template <typename T>
struct tree0 {
  using bound_t = int;
  static const int size = 100100;
  tree<T> fenwick[size];
  void update(bound_t posx, bound_t posy, T v) {
    for (posx++; posx < size; posx += posx & -posx)
      fenwick[posx].update(posy, v);
  }
  T sum(bound_t posx, bound_t ly, bound_t ry) {
    T ans = 0;
    for (posx++; posx; posx -= posx & -posx) ans += fenwick[posx].query(ly, ry);
    return ans;
  }
  T query(bound_t lx, bound_t rx, bound_t ly, bound_t ry) {
    return sum(rx, ly, ry) - sum(lx - 1, ly, ry);
  }
};
const int maxn = 100100;
set<int> pos[maxn];
int color[maxn];
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int e = 0; e < maxn; e++) pos[e].insert(n);
  for (int e = 0; e < n; e++) {
    int v;
    scanf("%d", &v);
    color[e] = v;
    pos[v].insert(e);
  }
  tree0<long long> solver;
  for (int e = 0; e < n; e++) {
    int nxt = *pos[color[e]].lower_bound(e + 1);
    solver.update(e, nxt, nxt - e);
  }
  for (int e = 0; e < q; e++) {
    int ty, l, r;
    scanf("%d %d %d", &ty, &l, &r);
    if (ty == 2) {
      l--;
      r--;
      printf("%lld\n", solver.query(l, r, l, r));
    } else {
      l--;
      {
        auto it = pos[color[l]].lower_bound(l + 1);
        int nxt = *it;
        solver.update(l, nxt, -nxt + l);
        pos[color[l]].erase(l);
      }
      {
        auto it = pos[color[l]].lower_bound(l);
        if (it != pos[color[l]].begin()) {
          it--;
          int bef = *it;
          int nxt = *pos[color[l]].lower_bound(bef + 1);
          solver.update(bef, l, -l + bef);
          solver.update(bef, nxt, nxt - bef);
        }
      }
      color[l] = r;
      {
        auto it = pos[color[l]].lower_bound(l);
        if (it != pos[color[l]].begin()) {
          it--;
          int bef = *it;
          int nxt = *pos[color[l]].lower_bound(bef + 1);
          solver.update(bef, nxt, -nxt + bef);
          solver.update(bef, l, l - bef);
        }
      }
      auto it = pos[color[l]].lower_bound(l);
      int nxt = *it;
      solver.update(l, nxt, nxt - l);
      pos[color[l]].insert(l);
    }
  }
  return 0;
}
