#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int inf = INT32_MAX;
struct Node {
  Node *l = 0, *r = 0;
  int m1 = inf, m2 = inf;
  Node(Node *a, Node *b) {
    l = a, r = b;
    m1 = min(l->m1, r->m1);
    m2 = min(max(l->m1, r->m1), min(l->m2, r->m2));
  }
  Node(Node *a, Node *b, int c) {
    l = a, r = b;
    m1 = c;
  }
};
Node *build(int l, int r, vector<int> &m) {
  if (l == r) return new Node(0, 0, m[l - 1]);
  int md = (l + r) / 2;
  return new Node(build(l, md, m), build(md + 1, r, m));
}
pair<int, int> que(int l, int r, int l1, int r1, Node *n) {
  if (l == l1 && r == r1) return {n->m1, n->m2};
  int md = (l1 + r1) / 2;
  if (r <= md) return que(l, r, l1, md, n->l);
  if (l > md) return que(l, r, md + 1, r1, n->r);
  pair<int, int> p1 = que(l, md, l1, md, n->l);
  pair<int, int> p2 = que(md + 1, r, md + 1, r1, n->r);
  return {min(p1.first, p2.first),
          min(max(p1.first, p2.first), min(p1.second, p2.second))};
}
void upd(int l, int r, int p, Node *n, int v) {
  if (l == r) {
    n->m1 = v;
    return;
  }
  int md = (l + r) / 2;
  if (p <= md)
    upd(l, md, p, n->l, v);
  else
    upd(md + 1, r, p, n->r, v);
  n->m1 = min(n->l->m1, n->r->m1);
  n->m2 = min(max(n->l->m1, n->r->m1), min(n->l->m2, n->r->m2));
}
int a, z;
vector<int> m;
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  cin >> a >> z;
  m = vector<int>(a);
  for (int q = 0; q < a; q++) cin >> m[q];
  vector<vector<int>> st(9, vector<int>(a));
  vector<Node *> n(9);
  for (int q = 0; q < a; q++) {
    for (int i = 0, w = m[q]; i < 9; i++, w /= 10) {
      st[i][q] = w % 10 ? m[q] : inf;
    }
  }
  for (int q = 0; q < 9; q++) n[q] = build(1, a, st[q]);
  for (; z; z--) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t == 1) {
      for (int q = 0, u = y; q < 9; q++, u /= 10) {
        upd(1, a, x, n[q], (u % 10 ? y : inf));
      }
    } else {
      int o = inf;
      for (int q = 0; q < 9; q++) {
        pair<int, int> p = que(x, y, 1, a, n[q]);
        if (p.second == inf) continue;
        o = min(o, p.first + p.second);
      }
      cout << (o == inf ? -1 : o) << "\n";
    }
  }
}
