#include <bits/stdc++.h>
using namespace std;
const int MAX = (2e5) + 10;
const int inf = -1;
pair<int, int> tree[4 * MAX];
void check(pair<int, int> &c, int v) {
  if (v == -1)
    return;
  else if (c.first == -1)
    c.first = v;
  else if (c.first > v)
    c.second = c.first, c.first = v;
  else if (c.second == -1)
    c.second = v;
  else
    c.second = min(c.second, v);
}
pair<int, int> mergeNode(pair<int, int> x, pair<int, int> y) {
  pair<int, int> ret = x;
  check(ret, y.first);
  check(ret, y.second);
  return ret;
}
void update(int idx, int b, int e, int p, int v) {
  if (p < b || p > e) return;
  if (b == e) {
    tree[idx] = {v, inf};
    return;
  }
  update((idx << 1), b, ((b + e) >> 1), p, v);
  update(((idx << 1) | 1), (((b + e) >> 1) + 1), e, p, v);
  tree[idx] = mergeNode(tree[(idx << 1)], tree[((idx << 1) | 1)]);
}
pair<int, int> query(int idx, int b, int e, int l, int r) {
  if (b > r || e < l) return {inf, inf};
  if (l <= b && e <= r) return tree[idx];
  return mergeNode(query((idx << 1), b, ((b + e) >> 1), l, r),
                   query(((idx << 1) | 1), (((b + e) >> 1) + 1), e, l, r));
}
void updatePos(int p, int v, int lev) {
  int org = (1e9), newVal = v, d = 0, i = 0;
  while (org) {
    int bit = newVal / org;
    if (bit) d |= (1 << i);
    newVal = newVal % org;
    i++;
    org /= 10;
  }
  for (int i = lev; i <= lev; i++) {
    if (d & (1 << i))
      update(1, 1, MAX, p, v);
    else
      update(1, 1, MAX, p, -1);
  }
}
int ara[MAX], show[MAX];
struct Node {
  int t, l, r;
} qr[MAX];
int main() {
  memset(tree, -1, sizeof(tree));
  memset(show, -1, sizeof(show));
  int n, u, v, l, r, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
  for (int i = 0; i < q; i++) scanf("%d %d %d", &qr[i].t, &qr[i].l, &qr[i].r);
  for (int lev = 0; lev < 10; lev++) {
    for (int i = 1; i <= n; i++) updatePos(i, ara[i], lev);
    for (int i = 0; i < q; i++) {
      int t = qr[i].t, l = qr[i].l, r = qr[i].r;
      if (t == 1)
        updatePos(l, r, lev);
      else {
        pair<int, int> x = query(1, 1, MAX, l, r);
        if (x.second == -1)
          continue;
        else
          show[i] = show[i] == -1 ? x.first + x.second
                                  : min(show[i], x.first + x.second);
      }
    }
  }
  for (int i = 0; i < q; i++)
    if (qr[i].t == 2) printf("%d\n", show[i]);
  return 0;
}
