#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int INF = INT_MAX / 2;
pair<int, int> tree[4 * N][9];
int n, a[N];
void push(int v) {
  for (int i = 0; i < 9; ++i) {
    tree[v][i] =
        tree[v * 2][i].first < tree[v * 2 + 1][i].first
            ? make_pair(tree[v * 2][i].first,
                        min(tree[v * 2][i].second, tree[v * 2 + 1][i].first))
            : make_pair(tree[v * 2 + 1][i].first,
                        min(tree[v * 2 + 1][i].second, tree[v * 2][i].first));
  }
}
void build(int v, int l, int r) {
  if (l == r) {
    for (int i = 0, x = a[l]; i < 9; ++i) {
      tree[v][i] = {x % 10 == 0 ? INF : a[l], INF};
      x /= 10;
    }
    return;
  }
  build(v * 2, l, (l + r) / 2);
  build(v * 2 + 1, (l + r) / 2 + 1, r);
  push(v);
}
void upd(int v, int l, int r, int idx, int x) {
  if (l == r) {
    for (int i = 0, y = x; i < 9; ++i) {
      tree[v][i].first = x % 10 == 0 ? INF : y;
      x /= 10;
    }
    return;
  }
  if ((l + r) / 2 < idx)
    upd(v * 2 + 1, (l + r) / 2 + 1, r, idx, x);
  else
    upd(v * 2, l, (l + r) / 2, idx, x);
  push(v);
}
vector<pair<int, int> > get(int v, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) {
    vector<pair<int, int> > ans(9);
    for (int i = 0; i < 9; i++) ans[i] = tree[v][i];
    return ans;
  }
  int m = (l + r) / 2;
  if (tr <= m)
    return get(v * 2, l, m, tl, tr);
  else if (tl > m)
    return get(v * 2 + 1, m + 1, r, tl, tr);
  vector<pair<int, int> > t1 = get(v * 2, l, m, tl, tr),
                          t2 = get(v * 2 + 1, m + 1, r, tl, tr);
  for (int i = 0; i < 9; i++) {
    if (t1[i].first > t2[i].first) swap(t1[i].first, t2[i].first);
    t1[i].second = min({t1[i].second, t2[i].first, t2[i].second});
  }
  return t1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int t, l, r;
    cin >> t >> l >> r;
    if (t == 1)
      upd(1, 1, n, l, r);
    else {
      vector<pair<int, int> > x = get(1, 1, n, l, r);
      int ans = INT_MAX;
      for (pair<int, int> it : x) {
        if (it.second != INF) ans = min(ans, it.first + it.second);
      }
      if (ans == INT_MAX)
        cout << "-1\n";
      else
        cout << ans << "\n";
    }
  }
  return 0;
}
