#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
const int inf = 0x3f3f3f3f;
struct ubs {
  int mnv[10], sec[10];
  ubs() {
    memset(mnv, 0x3f, sizeof mnv);
    memset(sec, 0x3f, sizeof sec);
  }
  ubs operator+(const ubs &b) const {
    ubs c;
    for (int i = 0; i <= 9; ++i) {
      int curm, curs;
      if (sec[i] < b.mnv[i])
        curm = mnv[i], curs = sec[i];
      else if (b.sec[i] < mnv[i])
        curm = b.mnv[i], curs = b.sec[i];
      else
        curm = min(mnv[i], b.mnv[i]), curs = max(mnv[i], b.mnv[i]);
      c.mnv[i] = curm;
      c.sec[i] = curs;
    }
    return c;
  }
};
int a[N];
struct segment_tree {
  ubs val[N * 4];
  inline void push_up(int x) { val[x] = val[x << 1] + val[x << 1 | 1]; }
  inline void insert(int x, int l, int r, int pos, int v) {
    if (l == r) {
      val[x] = ubs();
      int ov = v;
      for (int i = 0; i <= 9; ++i) {
        if (v % 10) val[x].mnv[i] = ov;
        v /= 10;
      }
      return;
    }
    if (pos <= (l + r) / 2)
      insert(x << 1, l, (l + r) / 2, pos, v);
    else
      insert(x << 1 | 1, (l + r) / 2 + 1, r, pos, v);
    push_up(x);
  }
  inline ubs query(int x, int l, int r, int ql, int qr) {
    if (ql > r || qr < l) return ubs();
    if (ql <= l && r <= qr) {
      return val[x];
    }
    return query(x << 1, l, (l + r) / 2, ql, qr) +
           query(x << 1 | 1, (l + r) / 2 + 1, r, ql, qr);
  }
} s;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    s.insert(1, 1, n, i, a[i]);
  }
  for (int i = 1; i <= m; ++i) {
    int id;
    scanf("%d", &id);
    if (id == 1) {
      int pos, v;
      scanf("%d%d", &pos, &v);
      s.insert(1, 1, n, pos, v);
    } else {
      int ql, qr;
      scanf("%d%d", &ql, &qr);
      ubs z = s.query(1, 1, n, ql, qr);
      int ans = 2000000000;
      for (int i = 0; i <= 9; ++i)
        if (z.sec[i] != inf) ans = min(ans, z.mnv[i] + z.sec[i]);
      if (ans == 2000000000)
        puts("-1");
      else
        printf("%d\n", ans);
    }
  }
  return 0;
}
