#include <bits/stdc++.h>
using namespace std;
struct node {
  node *l, *r;
  int Min, Min2;
  node() : l(NULL), r(NULL) {}
} * root[9];
void pull(node *n) {
  n->Min = min(n->l->Min, n->r->Min);
  if (n->Min == n->l->Min) {
    n->Min2 = min(n->l->Min2, n->r->Min);
  } else {
    n->Min2 = min(n->l->Min, n->r->Min2);
  }
}
void build(node *n, int *a, int l, int r) {
  if (l == r) {
    n->Min = a[l];
    n->Min2 = 1e9 + 7;
    return;
  }
  int mid = (l + r) / 2;
  n->l = new node();
  n->r = new node();
  build(n->l, a, l, mid);
  build(n->r, a, mid + 1, r);
  pull(n);
}
void revise(node *n, int k, int first, int l, int r) {
  if (l == r) {
    n->Min = first;
    return;
  }
  int mid = (l + r) / 2;
  if (k <= mid)
    revise(n->l, k, first, l, mid);
  else
    revise(n->r, k, first, mid + 1, r);
  pull(n);
}
pair<int, int> query(node *n, int l, int r, int ll, int rr) {
  if (ll >= l && rr <= r) {
    return make_pair(n->Min, n->Min2);
  }
  if (rr < l || ll > r) return make_pair(1e9 + 7, 1e9 + 7);
  int mid = (ll + rr) / 2;
  pair<int, int> p1 = query(n->l, l, r, ll, mid),
                 p2 = query(n->r, l, r, mid + 1, rr);
  int Min = min(p1.first, p2.first);
  int Min2;
  if (Min == p1.first) {
    Min2 = min(p1.second, p2.first);
  } else {
    Min2 = min(p1.first, p2.second);
  }
  return make_pair(Min, Min2);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int a[200005];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int tmp[200005];
  for (int i = 1; i <= n; i++) tmp[i] = a[i];
  int aa[200005];
  for (int i = 0; i < 9; i++) {
    for (int j = 1; j <= n; j++) {
      if (tmp[j] % 10)
        aa[j] = a[j];
      else
        aa[j] = 1e9 + 7;
      tmp[j] /= 10;
    }
    root[i] = new node();
    build(root[i], aa, 1, n);
  }
  while (m--) {
    int op, l, r;
    scanf("%d %d %d", &op, &l, &r);
    if (op == 1) {
      int first = r;
      a[l] = r;
      for (int j = 0; j < 9; j++) {
        if (first % 10) {
          revise(root[j], l, r, 1, n);
        } else {
          revise(root[j], l, 1e9 + 7, 1, n);
        }
        first /= 10;
      }
    } else {
      int ans = 2e9;
      for (int i = 0; i < 9; i++) {
        pair<int, int> p = query(root[i], l, r, 1, n);
        if (p.first < 1e9 && p.second < 1e9) ans = min(ans, p.first + p.second);
      }
      if (ans == 2e9) ans = -1;
      printf("%d\n", ans);
    }
  }
  return 0;
}
