#include <bits/stdc++.h>
using namespace std;
const long long ool = 1e18 + 9;
const int oo = 2e9 + 9, base = 1e9 + 7;
const double eps = 1e-7;
const int N = 2e5 + 6;
int n, m;
struct SegTree {
  pair<int, int> mn[N * 4];
  pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
    pair<int, int> res;
    if (a.first <= b.first) {
      res.first = a.first;
      res.second = min(b.first, a.second);
    } else {
      res.first = b.first;
      res.second = min(a.first, b.second);
    }
    return res;
  }
  void recalc(int v) { mn[v] = merge(mn[v << 1], mn[v << 1 | 1]); }
  void upd(int v, int tl, int tr, int pos, int val) {
    if (tl == tr - 1) {
      mn[v] = {val, oo};
      return;
    }
    int mid = (tl + tr) >> 1;
    if (pos < mid)
      upd(v << 1, tl, mid, pos, val);
    else
      upd(v << 1 | 1, mid, tr, pos, val);
    recalc(v);
  }
  pair<int, int> get(int v, int tl, int tr, int ql, int qr) {
    if (tr <= ql || qr <= tl) return {oo, oo};
    if (ql <= tl && tr <= qr) return mn[v];
    int mid = (tl + tr) >> 1;
    return merge(get(v << 1, tl, mid, ql, qr),
                 get(v << 1 | 1, mid, tr, ql, qr));
  }
} t[12];
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    long long deg = 1;
    for (int j = 1; j <= 10; ++j) {
      int digit = (x / deg) % 10;
      t[j].upd(1, 1, n + 1, i, (digit ? x : oo));
      deg *= 10;
    }
  }
  for (int i = 1; i <= m; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, x;
      cin >> pos >> x;
      long long deg = 1;
      for (int j = 1; j <= 10; ++j) {
        int digit = (x / deg) % 10;
        t[j].upd(1, 1, n + 1, pos, (digit ? x : oo));
        deg *= 10;
      }
    } else {
      int l, r;
      cin >> l >> r;
      int ans = oo;
      for (int j = 1; j <= 10; ++j) {
        pair<int, int> res = t[j].get(1, 1, n + 1, l, r + 1);
        if (res.first != oo && res.second != oo) {
          ans = min(ans, res.first + res.second);
        }
      }
      cout << (ans == oo ? -1 : ans) << "\n";
    }
  }
  return 0;
}
