#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int INF = 2000000005;
using namespace std;
mt19937 rng(1999999973);
const int N = 200000 + 5;
pair<int, int> t[4 * N][10];
int a[N], n, m, res[N], o = 0;
inline void init() {
  for (int i = 0; i < 4 * N; i++) {
    for (int j = 0; j < 10; j++) t[i][j] = make_pair(INF, INF);
  }
}
inline pair<int, int> getPair(pair<int, int> l, pair<int, int> r) {
  pair<int, int> ans;
  if (l.second < r.second) {
    ans.second = l.second;
    ans.first = min(l.first, r.second);
  } else {
    ans.second = r.second;
    ans.first = min(r.first, l.second);
  }
  return ans;
}
void update(int v, int tl, int tr, int pos, int val, int j) {
  if (!(pos >= tl && pos <= tr)) return;
  if (tl == tr) {
    t[v][j] = make_pair(INF, val);
    return;
  }
  int tm = (tl + tr) / 2;
  update(v * 2, tl, tm, pos, val, j);
  update(v * 2 + 1, tm + 1, tr, pos, val, j);
  t[v][j] = getPair(t[v * 2 + 1][j], t[v * 2][j]);
}
inline void add(int i, bool param = false) {
  int x = a[i];
  for (int j = 0; j < 10; j++) {
    if (x % 10 != 0) {
      update(1, 0, n - 1, i, a[i], j);
    } else {
      if (!param) update(1, 0, n - 1, i, INF, j);
    }
    x /= 10;
  }
}
pair<int, int> getAns(int v, int tl, int tr, int l, int r, int j) {
  if (tl > r || tr < l) return make_pair(INF, INF);
  if (tl >= l && tr <= r) return t[v][j];
  int tm = (tl + tr) / 2;
  return getPair(getAns(v * 2, tl, tm, l, r, j),
                 getAns(v * 2 + 1, tm + 1, tr, l, r, j));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  init();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    add(i, true);
  }
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int i, x;
      cin >> i >> x;
      i--;
      a[i] = x;
      add(i);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      long long ans = INF;
      for (int j = 0; j < 10; j++) {
        pair<int, int> cur = getAns(1, 0, n - 1, l, r, j);
        if ((long long)cur.first + (long long)cur.second < ans)
          ans = cur.first + cur.second;
      }
      if (ans == INF)
        res[o] = -1;
      else
        res[o] = (int)ans;
      o++;
    }
  }
  for (int i = 0; i < o; i++) cout << res[i] << '\n';
  return 0;
}

### Prompt

Please formulate a CPP solution to the following problem:

Let's define a balanced multiset the following way. Write down the sum of all elements of the multiset in its decimal representation. For each position of that number check if the multiset includes at least one element such that the digit of the element and the digit of the sum at that position are the same. If that holds for every position, then the multiset is balanced. Otherwise it's unbalanced.

For example, multiset \{20, 300, 10001\} is balanced and multiset \{20, 310, 10001\} is unbalanced: 

<image>

The red digits mark the elements and the positions for which these elements have the same digit as the sum. The sum of the first multiset is 10321, every position has the digit required. The sum of the second multiset is 10331 and the second-to-last digit doesn't appear in any number, thus making the multiset unbalanced.

You are given an array a_1, a_2, ..., a_n, consisting of n integers.

You are asked to perform some queries on it. The queries can be of two types:

  * 1~i~x — replace a_i with the value x; 
  * 2~l~r — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the minimum sum, or report that no unbalanced subset exists. 



Note that the empty multiset is balanced.

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5) — the number of elements in the array and the number of queries, respectively.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i < 10^9).

Each of the following m lines contains a query of one of two types:

  * 1~i~x (1 ≤ i ≤ n, 1 ≤ x < 10^9) — replace a_i with the value x; 
  * 2~l~r (1 ≤ l ≤ r ≤ n) — find the unbalanced subset of the multiset of the numbers a_l, a_{l + 1}, ..., a_r with the lowest sum, or report that no unbalanced subset exists. 



It is guaranteed that there is at least one query of the second type.

Output

For each query of the second type print the lowest sum of the unbalanced subset. Print -1 if no unbalanced subset exists.

Example

Input


4 5
300 10001 20 20
2 1 3
1 1 310
2 1 3
2 3 3
2 3 4


Output


-1
330
-1
40

Note

All the subsets of multiset \{20, 300, 10001\} are balanced, thus the answer is -1.

The possible unbalanced subsets in the third query are \{20, 310\} and \{20, 310, 10001\}. The lowest sum one is \{20, 310\}. Note that you are asked to choose a subset, not a subsegment, thus the chosen elements might not be adjancent in the array.

The fourth query includes only the empty subset and subset \{20\}. Both of them are balanced.

The last query includes the empty subset and the subsets \{20\}, \{20\} and \{20, 20\}. Only \{20, 20\} is unbalanced, its sum is 40. Note that you are asked to choose a multiset, thus it might include equal elements.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const int INF = 2000000005;
using namespace std;
mt19937 rng(1999999973);
const int N = 200000 + 5;
pair<int, int> t[4 * N][10];
int a[N], n, m, res[N], o = 0;
inline void init() {
  for (int i = 0; i < 4 * N; i++) {
    for (int j = 0; j < 10; j++) t[i][j] = make_pair(INF, INF);
  }
}
inline pair<int, int> getPair(pair<int, int> l, pair<int, int> r) {
  pair<int, int> ans;
  if (l.second < r.second) {
    ans.second = l.second;
    ans.first = min(l.first, r.second);
  } else {
    ans.second = r.second;
    ans.first = min(r.first, l.second);
  }
  return ans;
}
void update(int v, int tl, int tr, int pos, int val, int j) {
  if (!(pos >= tl && pos <= tr)) return;
  if (tl == tr) {
    t[v][j] = make_pair(INF, val);
    return;
  }
  int tm = (tl + tr) / 2;
  update(v * 2, tl, tm, pos, val, j);
  update(v * 2 + 1, tm + 1, tr, pos, val, j);
  t[v][j] = getPair(t[v * 2 + 1][j], t[v * 2][j]);
}
inline void add(int i, bool param = false) {
  int x = a[i];
  for (int j = 0; j < 10; j++) {
    if (x % 10 != 0) {
      update(1, 0, n - 1, i, a[i], j);
    } else {
      if (!param) update(1, 0, n - 1, i, INF, j);
    }
    x /= 10;
  }
}
pair<int, int> getAns(int v, int tl, int tr, int l, int r, int j) {
  if (tl > r || tr < l) return make_pair(INF, INF);
  if (tl >= l && tr <= r) return t[v][j];
  int tm = (tl + tr) / 2;
  return getPair(getAns(v * 2, tl, tm, l, r, j),
                 getAns(v * 2 + 1, tm + 1, tr, l, r, j));
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  init();
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    add(i, true);
  }
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int i, x;
      cin >> i >> x;
      i--;
      a[i] = x;
      add(i);
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      long long ans = INF;
      for (int j = 0; j < 10; j++) {
        pair<int, int> cur = getAns(1, 0, n - 1, l, r, j);
        if ((long long)cur.first + (long long)cur.second < ans)
          ans = cur.first + cur.second;
      }
      if (ans == INF)
        res[o] = -1;
      else
        res[o] = (int)ans;
      o++;
    }
  }
  for (int i = 0; i < o; i++) cout << res[i] << '\n';
  return 0;
}

```