#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
int seg[800006][16], x[800006], n, m, t, p, T, ans, pc, L, R, k;
vector<int> v;
inline int gt(int a, int b) {
  int k1 = (pow(10, b));
  int k2 = (pow(10, b - 1));
  if ((k1 % 10) == 9) k1++;
  if ((k2 % 10) == 9) k2++;
  return ((a % k1) / (k2));
}
inline int Build_Segtree(int h, int l, int r) {
  if (l > r) return 0;
  if (l > R) return seg[h][k];
  if (r < L) return seg[h][k];
  if (l == r) {
    if (gt(x[l], k))
      return seg[h][k] = l;
    else
      return seg[h][k] = 0;
  }
  int lf = Build_Segtree(h << 1, l, ((l + r) >> 1));
  int rg = Build_Segtree((h << 1) + 1, ((l + r) >> 1) + 1, r);
  if (x[lf] > x[rg]) return seg[h][k] = rg;
  if (x[lf] <= x[rg]) return seg[h][k] = lf;
}
inline int get(int h, int l, int r) {
  if (l > r) return 0;
  if (l > R) return 0;
  if (r < L) return 0;
  if (l >= L && r <= R) return seg[h][k];
  int lf = get(h << 1, l, ((l + r) >> 1));
  int rg = get((h << 1) + 1, ((l + r) >> 1) + 1, r);
  if (x[lf] > x[rg]) return rg;
  if (x[lf] <= x[rg]) return lf;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  x[0] = 1999999999;
  for (int j = 1; j <= 9; j++) {
    L = 1;
    R = n;
    k = j;
    Build_Segtree(1, 1, n);
  }
  for (int i = 1; i <= m; i++) {
    int q, a, b;
    cin >> q >> a >> b;
    if (q == 1) {
      x[a] = b;
      for (int j = 1; j <= 9; j++) {
        L = a;
        R = a;
        k = j;
        Build_Segtree(1, 1, n);
      }
    }
    if (q == 2) {
      ans = 1999999999;
      for (int j = 1; j <= 9; j++) {
        L = a;
        R = b;
        k = j;
        t = get(1, 1, n);
        p = x[t];
        x[t] = 0;
        L = t;
        R = t;
        k = j;
        Build_Segtree(1, 1, n);
        L = a;
        R = b;
        k = j;
        T = get(1, 1, n);
        x[t] = p;
        L = t;
        R = t;
        k = j;
        Build_Segtree(1, 1, n);
        if (T) ans = min(ans, x[t] + x[T]);
      }
      if (ans == 1999999999) {
        v.push_back(-1);
      } else {
        v.push_back(ans);
      }
    }
  }
  for (int i = 0; i < v.size(); i++) {
    printf("%ld \n", v[i]);
  }
}
