#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;
const int logn = 10 + 2;
int add(int x, int y) {
  x += y;
  return x >= mod ? x - mod : x;
}
int sub(int x, int y) {
  x -= y;
  return x < 0 ? x + mod : x;
}
int mul(int x, int y) { return 1LL * x * y % mod; }
int a[maxn], mn[maxn << 2][logn], mn2[maxn << 2][logn], ans, ans2;
void pushup(int o) {
  for (int d = 0; d < 10; d++) {
    mn[o][d] = min(mn[o << 1][d], mn[o << 1 | 1][d]);
    if (mn[o << 1][d] <= mn[o << 1 | 1][d])
      mn2[o][d] = min(mn2[o << 1][d], mn[o << 1 | 1][d]);
    else
      mn2[o][d] = min(mn[o << 1][d], mn2[o << 1 | 1][d]);
  }
}
void build(int o, int l, int r) {
  for (int d = 0; d < 10; d++) mn[o][d] = mn2[o][d] = INT_MAX;
  if (l == r) {
    int d = 0, now = a[l];
    while (now) {
      if (now % 10) mn[o][d] = a[l];
      d++, now /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);
  pushup(o);
}
void update(int o, int l, int r, int pos, int v) {
  for (int d = 0; d < 10; d++) mn[o][d] = mn2[o][d] = INT_MAX;
  if (l == r) {
    int d = 0, now = v;
    while (now) {
      if (now % 10) mn[o][d] = v;
      d++, now /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(o << 1, l, mid, pos, v);
  else
    update(o << 1 | 1, mid + 1, r, pos, v);
  pushup(o);
}
void query(int o, int l, int r, int ll, int rr, int d) {
  if (ll <= l && r <= rr) {
    if (mn[o][d] < ans)
      ans2 = min(ans, mn2[o][d]), ans = mn[o][d];
    else if (mn[o][d] < ans2)
      ans2 = mn[o][d];
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) query(o << 1, l, mid, ll, rr, d);
  if (rr > mid) query(o << 1 | 1, mid + 1, r, ll, rr, d);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  while (m--) {
    int op;
    cin >> op;
    if (op == 1) {
      int i, x;
      cin >> i >> x;
      update(1, 1, n, i, x);
    } else {
      int l, r, res = INT_MAX;
      cin >> l >> r;
      for (int d = 0; d < 10; d++) {
        ans = ans2 = INT_MAX;
        query(1, 1, n, l, r, d);
        if (ans2 != INT_MAX) res = min(res, ans + ans2);
      }
      if (res != INT_MAX)
        cout << res << endl;
      else
        cout << -1 << endl;
    }
  }
  return 0;
}
