#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010, INF = 2e9 + 9;
int f[MAXN * 4][9], n, m, ans[MAXN * 4], t, queans, t2, tmp[9];
int merge(int x[], int l[], int r[]) {
  int mn = INF;
  for (int i = 0; i < 9; ++i) {
    if (l[i] != INF && r[i] != INF) {
      mn = min(mn, l[i] + r[i]);
    }
    x[i] = min(l[i], r[i]);
  }
  return mn;
}
void upd(int x, int l, int r, int ll, int val) {
  if (l == r) {
    for (int i = 0; i < 9; ++i) f[x][i] = INF;
    t = val;
    for (int i = 0; t; ++i) {
      if (t % 10 != 0) f[x][i] = val;
      t /= 10;
    }
    return;
  }
  int md = (l + r) / 2;
  if (ll > md)
    upd(x * 2 + 1, md + 1, r, ll, val);
  else
    upd(x * 2, l, md, ll, val);
  ans[x] = min(ans[x * 2], ans[x * 2 + 1]);
  ans[x] = min(ans[x], merge(f[x], f[x * 2], f[x * 2 + 1]));
}
void que(int x, int l, int r, int ll, int rr, int cur[]) {
  if (l > rr || r < ll) return;
  if (l >= ll && r <= rr) {
    queans = min(queans, min(ans[x], merge(cur, cur, f[x])));
    return;
  }
  int md = (l + r) / 2;
  que(x * 2, l, md, ll, rr, cur);
  que(x * 2 + 1, md + 1, r, ll, rr, cur);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 0; i < MAXN * 4; ++i) {
    ans[i] = INF;
    for (int j = 0; j < 9; ++j) f[i][j] = INF;
  }
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> t;
    upd(1, 1, n, i, t);
  }
  for (int i = 0; i < m; ++i) {
    cin >> t;
    if (t == 1) {
      cin >> t >> t2;
      upd(1, 1, n, t, t2);
    } else {
      cin >> t >> t2;
      queans = INF;
      for (int j = 0; j < 9; ++j) tmp[j] = INF;
      que(1, 1, n, t, t2, tmp);
      if (queans == INF)
        cout << -1 << '\n';
      else
        cout << queans << '\n';
    }
  }
}
