#include <bits/stdc++.h>
using namespace std;
const long long maxn = (1 << 18);
pair<long long, long long> tree[10][2 * maxn];
void upd(long long k, long long v, long long t) {
  k += maxn;
  tree[t][k] = {v, k - maxn};
  for (long long i = k / 2; i >= 1; i /= 2)
    tree[t][i] = min(tree[t][i * 2], tree[t][i * 2 + 1]);
}
pair<long long, long long> qry(long long l, long long r, long long t) {
  l += maxn, r += maxn;
  pair<long long, long long> res = {1e18, 1e18};
  while (l <= r) {
    if (l % 2 == 1) res = min(res, tree[t][l++]);
    if (r % 2 == 0) res = min(res, tree[t][r--]);
    l /= 2, r /= 2;
  }
  return res;
}
void replace(long long k, long long x) {
  string s = to_string(x);
  for (long long i = 0; i < 10; i++) upd(k, 1e18, i);
  for (long long i = s.length() - 1; i >= 0; i--) {
    long long d = s.length() - i - 1;
    if (s[i] == '0')
      upd(k, 1e18, d);
    else
      upd(k, x, d);
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (long long i = 0; i < 10; i++)
    for (long long j = 0; j < 2 * maxn; j++) tree[i][j] = {1e18, 1e18};
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    replace(i, x);
  }
  for (long long i = 0; i < m; i++) {
    long long t;
    cin >> t;
    if (t == 1) {
      long long k, x;
      cin >> k >> x;
      replace(k, x);
    } else {
      long long l, r;
      cin >> l >> r;
      if (l == r) {
        cout << "-1\n";
        continue;
      }
      long long res = 1e18;
      for (long long d = 0; d < 10; d++) {
        pair<long long, long long> firstMini = qry(l, r, d);
        if (firstMini.first == 1e18) continue;
        pair<long long, long long> secondMini = {1e18, 1e18};
        if (firstMini.second != l)
          secondMini = min(secondMini, qry(l, firstMini.second - 1, d));
        if (firstMini.second != r)
          secondMini = min(secondMini, qry(firstMini.second + 1, r, d));
        if (secondMini.first == 1e18) continue;
        res = min(res, firstMini.first + secondMini.first);
      }
      if (res == 1e18)
        cout << "-1\n";
      else
        cout << res << '\n';
    }
  }
}
