#include <bits/stdc++.h>
using namespace std;
int n, m, a[500001], f[1000001][10][2], g[1000001][2], fac[101];
void pushup(int x) {
  int i;
  for (i = 0; i < 10; i++) {
    if (f[x * 2][i][0] < f[x * 2 + 1][i][0]) {
      f[x][i][0] = f[x * 2][i][0];
      f[x][i][1] = min(f[x * 2][i][1], f[x * 2 + 1][i][0]);
    } else {
      f[x][i][0] = f[x * 2 + 1][i][0];
      f[x][i][1] = min(f[x * 2 + 1][i][1], f[x * 2][i][0]);
    }
  }
}
void build(int x, int l, int r) {
  int hh, i;
  if (l == r) {
    for (i = 0; i < 10; i++) {
      f[x][i][0] = f[x][i][1] = 1e9;
      hh = a[l] / fac[i] % 10;
      if (hh != 0) f[x][i][0] = a[l];
    }
    return;
  }
  int mid = (l + r) / 2;
  build(x * 2, l, mid);
  build(x * 2 + 1, mid + 1, r);
  pushup(x);
}
void ins(int x, int l, int r, int t) {
  int i, hh;
  if (l == r) {
    for (i = 0; i < 10; i++) {
      f[x][i][0] = f[x][i][1] = 1e9;
      hh = a[l] / fac[i] % 10;
      if (hh != 0) f[x][i][0] = a[l];
    }
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= t)
    ins(x * 2, l, mid, t);
  else
    ins(x * 2 + 1, mid + 1, r, t);
  pushup(x);
}
void query(int x, int l, int r, int t, int k, int w) {
  if (l == t && r == k) {
    g[x][0] = f[x][w][0];
    g[x][1] = f[x][w][1];
    return;
  }
  int mid = (l + r) / 2;
  if (mid >= k) {
    query(x * 2, l, mid, t, k, w);
    g[x][0] = g[x * 2][0];
    g[x][1] = g[x * 2][1];
  } else if (t > mid) {
    query(x * 2 + 1, mid + 1, r, t, k, w);
    g[x][0] = g[x * 2 + 1][0];
    g[x][1] = g[x * 2 + 1][1];
  } else {
    query(x * 2, l, mid, t, mid, w);
    query(x * 2 + 1, mid + 1, r, mid + 1, k, w);
    if (g[x * 2][0] < g[x * 2 + 1][0]) {
      g[x][0] = g[x * 2][0];
      g[x][1] = min(g[x * 2][1], g[x * 2 + 1][0]);
    } else {
      g[x][0] = g[x * 2 + 1][0];
      g[x][1] = min(g[x * 2 + 1][1], g[x * 2][0]);
    }
  }
}
int main() {
  int i, l, r, op, ans;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  fac[0] = 1;
  for (i = 1; i <= 9; i++) fac[i] = fac[i - 1] * 10;
  build(1, 1, n);
  while (m--) {
    scanf("%d%d%d", &op, &l, &r);
    if (op == 1) {
      a[l] = r;
      ins(1, 1, n, l);
    } else {
      ans = 2e9;
      for (i = 0; i < 10; i++) {
        query(1, 1, n, l, r, i);
        if (g[1][1] == 1e9) continue;
        ans = min(ans, g[1][0] + g[1][1]);
      }
      if (ans == 2e9)
        puts("-1");
      else
        printf("%d\n", ans);
    }
  }
}
