#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 2e5 + 5;
const int oo = 2e9 + 7;
pair<int, int> mer(pair<int, int> x, pair<int, int> y) {
  pair<int, int> ret = {min(x.first, y.first), max(x.first, y.first)};
  ret.second = min(ret.second, y.second);
  ret.second = min(ret.second, x.second);
  return ret;
}
void UpdatePoint(int node, int ss, int se, int u, int diff,
                 pair<int, int> *value) {
  if (ss > se || ss > u || se < u) return;
  int mid = ss + (se - ss) / 2;
  if (ss == se && ss == u) {
    value[node] = {diff, oo};
    return;
  }
  UpdatePoint(node << 1, ss, mid, u, diff, value);
  UpdatePoint((node << 1) + 1, mid + 1, se, u, diff, value);
  value[node] = mer(value[node << 1], value[(node << 1) + 1]);
}
pair<int, int> Getmer(int node, int ss, int se, int qs, int qe,
                      pair<int, int> *value) {
  int mid = ss + (se - ss) / 2;
  if (ss > se || ss > qe || se < qs || qs > qe) return {oo, oo};
  if (ss >= qs && se <= qe) return value[node];
  return mer(Getmer(node << 1, ss, mid, qs, qe, value),
             Getmer((node << 1) + 1, mid + 1, se, qs, qe, value));
}
void Build(int node, int *a, int ss, int se, pair<int, int> *value) {
  if (ss == se) {
    value[node] = {a[ss], oo};
    return;
  }
  int mid = ss + (se - ss) / 2;
  Build(node << 1, a, ss, mid, value);
  Build((node << 1) + 1, a, mid + 1, se, value);
  value[node] = mer(value[node << 1], value[(node << 1) + 1]);
}
pair<int, int> value[11][4 * N];
int a[N];
int aa[11][N];
int32_t main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= 10; j++) aa[j][i] = oo;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    int x = a[i];
    for (int k = 0; k <= 10; k++) {
      if (x % 10) {
        aa[k][i] = a[i];
      }
      x /= 10;
    }
  }
  for (int j = 0; j <= 10; j++) {
    Build(1, aa[j], 1, n, value[j]);
  }
  while (m--) {
    int c;
    scanf("%d", &c);
    if (c == 1) {
      int i, x;
      scanf("%d %d", &i, &x);
      a[i] = x;
      for (int k = 0; k <= 10; k++) {
        if (x % 10) {
          UpdatePoint(1, 1, n, i, a[i], value[k]);
        } else
          UpdatePoint(1, 1, n, i, oo, value[k]);
        x /= 10;
      }
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      int ans = oo;
      for (int i = 0; i <= 10; i++) {
        pair<int, int> x = Getmer(1, 1, n, l, r, value[i]);
        if (x.first == oo or x.second == oo) continue;
        ans = min(ans, x.first + x.second);
      }
      if (ans == oo)
        printf("-1\n");
      else
        printf("%d\n", ans);
    }
  }
}
