#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int N = 200003;
inline pair<int, int> Add(pair<int, int> x, pair<int, int> y) {
  pair<int, int> ret;
  ret.first = min(x.first, y.first);
  ret.second = min(x.second, y.second);
  ret.second = min(ret.second, max(x.first, y.first));
  return ret;
}
struct Bin_Tree {
  pair<int, int> Mn[4 * N];
  void Pushup(int rt) { Mn[rt] = Add(Mn[(rt << 1)], Mn[((rt << 1) | 1)]); }
  void Change(int rt, int p, int val, int l, int r) {
    if (l == r) {
      Mn[rt].first = val;
      Mn[rt].second = INF;
      return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid)
      Change((rt << 1), p, val, l, mid);
    else
      Change(((rt << 1) | 1), p, val, mid + 1, r);
    Pushup(rt);
  }
  pair<int, int> Query(int rt, int L, int R, int l, int r) {
    if (L <= l && r <= R) return Mn[rt];
    int mid = (l + r) >> 1;
    if (R <= mid) return Query((rt << 1), L, R, l, mid);
    if (L > mid) return Query(((rt << 1) | 1), L, R, mid + 1, r);
    return Add(Query((rt << 1), L, R, l, mid),
               Query(((rt << 1) | 1), L, R, mid + 1, r));
  }
} T[10];
int n, q;
int cf[10];
int main() {
  cf[0] = 1;
  for (int i = 1; i < 10; i++) cf[i] = 10 * cf[i - 1];
  scanf("%d %d", &n, &q);
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    for (int j = 0; j < 9; j++) {
      if (a % cf[j + 1] / cf[j])
        T[j].Change(1, i, a, 1, n);
      else
        T[j].Change(1, i, INF, 1, n);
    }
  }
  for (int i = 1, opt, l, r; i <= q; i++) {
    scanf("%d %d %d", &opt, &l, &r);
    if (opt == 1) {
      for (int j = 0; j < 9; j++) {
        if (r % cf[j + 1] / cf[j])
          T[j].Change(1, l, r, 1, n);
        else
          T[j].Change(1, l, INF, 1, n);
      }
    } else {
      opt = 2 * INF;
      for (int j = 0; j < 9; j++) {
        pair<int, int> f = T[j].Query(1, l, r, 1, n);
        if (f.second >= INF) continue;
        if (f.first + f.second < opt) opt = f.first + f.second;
      }
      if (opt >= 2 * INF)
        printf("-1\n");
      else
        printf("%d\n", opt);
    }
  }
  return 0;
}
