#include <bits/stdc++.h>
using namespace std;
pair<int, int> get(pair<int, int> x, int v) {
  if (v < x.first)
    x.second = x.first, x.first = v;
  else
    x.second = min(x.second, v);
  return x;
}
pair<int, int> oper(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ans = get(a, b.first);
  ans = get(ans, b.second);
  return ans;
}
int INF = 2e9 + 10;
pair<int, int> NEUT = {INF, INF};
struct STree {
  vector<pair<int, int> > t;
  int n;
  STree() {}
  STree(int n) : n(n), t(2 * n + 5, NEUT) {}
  void upd(int p, int value) {
    for (t[p += n] = {value, INF}; p > 1; p >>= 1)
      t[p >> 1] = oper(t[p], t[p ^ 1]);
  }
  pair<int, int> query(int l, int r) {
    pair<int, int> res = NEUT;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) res = oper(res, t[l++]);
      if (r & 1) res = oper(res, t[--r]);
    }
    return res;
  }
};
STree st[11];
void add(int x, int pos) {
  int xx = x;
  for (int i = 0, ThxDem = 11; i < ThxDem; ++i) {
    if (x % 10)
      st[i].upd(pos, xx);
    else
      st[i].upd(pos, INF);
    x /= 10;
  }
}
int a[200010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0, ThxDem = 11; i < ThxDem; ++i) st[i] = STree(n);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) cin >> a[i], add(a[i], i);
  while (m--) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, x;
      cin >> l >> x;
      add(x, l - 1);
    } else {
      int l, r;
      cin >> l >> r;
      int ans = INF;
      for (int i = 0, ThxDem = 11; i < ThxDem; ++i) {
        pair<int, int> now = st[i].query(l - 1, r);
        if (now.first == INF || now.second == INF) continue;
        ans = min(ans, now.first + now.second);
      }
      if (ans == INF)
        cout << -1 << "\n";
      else
        cout << ans << "\n";
    }
  }
}
