#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
int a[N];
const long long inf = (long long)1e14;
inline pair<long long, long long> merge(pair<long long, long long> &x,
                                        pair<long long, long long> &y) {
  return {min(x.first, y.first),
          min(max(x.first, y.first), min(x.second, y.second))};
}
struct SegTree {
  vector<pair<long long, long long> > T;
  int n;
  SegTree(int _n) {
    n = _n;
    T.resize(2 * n, {inf, inf});
  }
  void update(int pos, long long val) {
    for (T[pos += n].first = val; pos > 1; pos >>= 1) {
      T[pos >> 1] = merge(T[pos], T[pos ^ 1]);
    }
  }
  pair<long long, long long> query(int l, int r) {
    r++;
    pair<long long, long long> ans = {inf, inf};
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans = merge(ans, T[l++]);
      if (r & 1) ans = merge(ans, T[--r]);
    }
    return ans;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  vector<SegTree> sg(10, SegTree(2 * n));
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    cin >> a[i];
    int val = a[i];
    for (int(j) = 0; (j) < (int)(10); ++(j)) {
      if (val % 10) {
        sg[j].update(i, a[i]);
      }
      val /= 10;
    }
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, x;
      cin >> pos >> x;
      pos--;
      for (int(j) = 0; (j) < (int)(10); ++(j)) {
        if (a[pos] % 10) {
          sg[j].update(pos, inf);
        }
        a[pos] /= 10;
      }
      a[pos] = x;
      for (int(j) = 0; (j) < (int)(10); ++(j)) {
        if (x % 10) {
          sg[j].update(pos, a[pos]);
        }
        x /= 10;
      }
    } else {
      int l, r;
      cin >> l >> r;
      l--, r--;
      long long ans = inf;
      for (int(j) = 0; (j) < (int)(10); ++(j)) {
        pair<long long, long long> cur = sg[j].query(l, r);
        ans = min(ans, cur.first + cur.second);
      }
      if (ans > 2 * (1e9)) {
        ans = -1;
      }
      cout << ans << '\n';
    }
  }
}
