#include <bits/stdc++.h>
using namespace std;
const int maxn = 222222;
const int inf = 0x3f3f3f3f;
int a[maxn];
int anum[maxn][11];
pair<int, int> getmin(pair<int, int> p1, pair<int, int> p2) {
  if (p1.first == inf) {
    return p2;
  }
  if (p2.first == inf) {
    return p1;
  }
  if (p1.first < p2.first) {
    pair<int, int> ans(p1);
    if (p2.first < ans.second) ans.second = p2.first;
    return ans;
  } else {
    pair<int, int> ans(p2);
    if (p1.first < ans.second) ans.second = p1.first;
    return ans;
  }
}
struct Seg {
  pair<int, int> mi[maxn << 2];
  void up(int rt) { mi[rt] = getmin(mi[rt << 1], mi[rt << 1 | 1]); }
  void build(int l, int r, int rt, int k) {
    if (l == r) {
      if (anum[l][k]) {
        mi[rt] = make_pair(a[l], inf);
      } else {
        mi[rt] = make_pair(inf, inf);
      }
      return;
    }
    int m = (l + r) >> 1;
    build(l, m, rt << 1, k);
    build(m + 1, r, rt << 1 | 1, k);
    up(rt);
  }
  pair<int, int> query(int L, int R, int l, int r, int rt) {
    if (L <= l && R >= r) {
      return mi[rt];
    }
    int m = (l + r) >> 1;
    pair<int, int> ans = make_pair(inf, inf);
    if (L <= m) ans = getmin(ans, query(L, R, l, m, rt << 1));
    if (R > m) ans = getmin(ans, query(L, R, m + 1, r, rt << 1 | 1));
    return ans;
  }
  void update(int p, int x, int l, int r, int rt, int k) {
    if (p == l && p == r) {
      if (anum[p][k]) {
        mi[rt] = make_pair(x, inf);
      } else {
        mi[rt] = make_pair(inf, inf);
      }
      return;
    }
    int m = (l + r) >> 1;
    if (p <= m)
      update(p, x, l, m, rt << 1, k);
    else
      update(p, x, m + 1, r, rt << 1 | 1, k);
    up(rt);
  }
};
Seg seg[11];
int n, m;
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      int x = a[i];
      for (int j = 0; j < 10; j++) {
        anum[i][j] = x % 10;
        x /= 10;
      }
    }
    for (int bit = 0; bit < 10; bit++) seg[bit].build(1, n, 1, bit);
    while (m--) {
      int op, x, y;
      cin >> op >> x >> y;
      if (op == 1) {
        a[x] = y;
        int now = y;
        for (int j = 0; j < 10; j++) {
          anum[x][j] = now % 10;
          now /= 10;
        }
        for (int bit = 0; bit < 10; bit++) seg[bit].update(x, y, 1, n, 1, bit);
      } else {
        int l = x, r = y;
        int ans = 2e9 + 1;
        for (int bit = 0; bit < 10; bit++) {
          pair<int, int> res = seg[bit].query(l, r, 1, n, 1);
          if (res.first != inf && res.second != inf)
            ans = min(ans, res.first + res.second);
        }
        if (ans == 2e9 + 1) ans = -1;
        cout << ans << endl;
      }
    }
  }
  return 0;
}
