#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
int n, m, a[maxn], g[10];
struct mmp {
  int x[10], y[10];
} tr[maxn * 4];
void cmb(mmp &z, mmp x, mmp y) {
  for (int i = 0; i <= 9; i++) {
    z.x[i] = min(x.x[i], y.x[i]);
    z.y[i] = min(max(x.x[i], y.x[i]), min(x.y[i], y.y[i]));
  }
}
void build(int num, int l, int r) {
  if (l == r) {
    for (int i = 0; i <= 9; i++) {
      int p = a[l] / g[i] % 10;
      if (p)
        tr[num].x[i] = a[l];
      else
        tr[num].x[i] = mod;
      tr[num].y[i] = mod;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(num * 2, l, mid);
  build(num * 2 + 1, mid + 1, r);
  cmb(tr[num], tr[num * 2], tr[num * 2 + 1]);
}
void putin(int num, int l, int r, int x) {
  if (l == r) {
    for (int i = 0; i <= 9; i++) {
      int p = a[l] / g[i] % 10;
      if (p)
        tr[num].x[i] = a[l];
      else
        tr[num].x[i] = mod;
      tr[num].y[i] = mod;
    }
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid)
    putin(num * 2, l, mid, x);
  else
    putin(num * 2 + 1, mid + 1, r, x);
  cmb(tr[num], tr[num * 2], tr[num * 2 + 1]);
}
mmp getout(int num, int l, int r, int x, int y) {
  if (x <= l && r <= y) return tr[num];
  int mid = (l + r) / 2;
  if (y <= mid)
    return getout(num * 2, l, mid, x, y);
  else if (x >= mid + 1)
    return getout(num * 2 + 1, mid + 1, r, x, y);
  else {
    mmp ret;
    cmb(ret, getout(num * 2, l, mid, x, y),
        getout(num * 2 + 1, mid + 1, r, x, y));
    return ret;
  }
}
int main() {
  int i, j, k, x, y, mi;
  cin >> n >> m;
  g[0] = 1;
  for (i = 1; i <= 9; i++) g[i] = g[i - 1] * 10;
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &k, &x, &y);
    if (k == 1) {
      a[x] = y;
      putin(1, 1, n, x);
    } else {
      mmp ret = getout(1, 1, n, x, y);
      mi = mod * 2;
      for (j = 0; j <= 9; j++)
        if (max(ret.x[j], ret.y[j]) < mod) mi = min(mi, ret.x[j] + ret.y[j]);
      if (mi == mod * 2)
        printf("-1\n");
      else
        printf("%d\n", mi);
    }
  }
  return 0;
}
