#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
int n, q, z, zz, type, c, d;
pair<int, int> seg[12][maxn];
pair<int, int> ans;
int a[maxn];
pair<int, int> pull(pair<int, int> X, pair<int, int> Y) {
  pair<int, int> ret;
  if (X.first < Y.first) {
    ret.first = X.first;
    ret.second = min(X.second, Y.first);
  } else {
    ret.first = Y.first;
    ret.second = min(Y.second, X.first);
  }
  return ret;
}
void modify(int id, int now, int l, int r, int x, int v) {
  if (l == r) {
    seg[id][now] = make_pair(v, inf);
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    modify(id, now * 2, l, m, x, v);
  else
    modify(id, now * 2 + 1, m + 1, r, x, v);
  seg[id][now] = pull(seg[id][now * 2], seg[id][now * 2 + 1]);
}
void query(int id, int now, int l, int r, int ql, int qr) {
  if (r < ql || l > qr)
    return;
  else if (l >= ql && r <= qr) {
    ans = pull(ans, seg[id][now]);
    return;
  }
  int m = (l + r) >> 1;
  query(id, now * 2, l, m, ql, qr);
  query(id, now * 2 + 1, m + 1, r, ql, qr);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 0; i <= 10; i++)
    for (int j = 0; j <= 4 * n + 2; j++) seg[i][j] = make_pair(inf, inf);
  for (int i = 1; i <= n; i++) {
    cin >> z;
    a[i] = zz = z;
    for (int j = 0; j <= 10; j++) {
      if (zz % 10 != 0) modify(j, 1, 1, n, i, z);
      zz /= 10;
    }
  }
  for (int i = 1; i <= q; i++) {
    cin >> type >> c >> d;
    if (type == 2) {
      int ret = inf;
      for (int j = 0; j <= 10; j++) {
        ans = make_pair(inf, inf);
        query(j, 1, 1, n, c, d);
        if (ans.second != inf) ret = min(ret, ans.first + ans.second);
      }
      if (ret == inf)
        cout << -1 << '\n';
      else
        cout << ret << '\n';
    } else {
      a[c] = d;
      for (int j = 0; j <= 10; j++) {
        modify(j, 1, 1, n, c, inf);
        if (d % 10 != 0) modify(j, 1, 1, n, c, a[c]);
        d /= 10;
      }
    }
  }
}
