#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct node {
  long long ans;
  long long mn[10];
  node() {
    ans = 0x3f3f3f3f3f3f3f3f;
    for (int i = 0; i < 10; i++) mn[i] = 0x3f3f3f3f3f3f3f3f;
  };
} tree[maxn << 2];
int a[maxn], n, m;
void pushup(int rt) {
  tree[rt].ans = min(tree[rt << 1].ans, tree[rt << 1 | 1].ans);
  for (int i = 0; i < 10; i++) {
    tree[rt].mn[i] = min(tree[rt << 1].mn[i], tree[rt << 1 | 1].mn[i]);
    if (tree[rt << 1].mn[i] != 0x3f3f3f3f3f3f3f3f &&
        tree[rt << 1 | 1].mn[i] != 0x3f3f3f3f3f3f3f3f) {
      tree[rt].ans =
          min(tree[rt].ans, tree[rt << 1].mn[i] + tree[rt << 1 | 1].mn[i]);
    }
  }
}
void build(int rt, int l, int r) {
  if (l == r) {
    tree[rt] = node();
    int val = a[l], num, i = 0;
    while (val) {
      num = val % 10;
      if (num) tree[rt].mn[i] = a[l];
      val /= 10;
      i++;
    }
    return;
  }
  int m = (l + r) >> 1;
  build(rt << 1, l, m);
  build(rt << 1 | 1, m + 1, r);
  pushup(rt);
}
void update(int rt, int l, int r, int pos, int val) {
  if (l == r) {
    tree[rt] = node();
    a[l] = val;
    int num, i = 0;
    while (val) {
      num = val % 10;
      if (num) tree[rt].mn[i] = a[l];
      val /= 10;
      i++;
    }
    return;
  }
  int m = (l + r) >> 1;
  if (pos <= m)
    update(rt << 1, l, m, pos, val);
  else
    update(rt << 1 | 1, m + 1, r, pos, val);
  pushup(rt);
}
void merge(node &a, node b) {
  a.ans = min(a.ans, b.ans);
  for (int i = 0; i < 10; i++) {
    if (a.mn[i] != 0x3f3f3f3f3f3f3f3f && b.mn[i] != 0x3f3f3f3f3f3f3f3f)
      a.ans = min(a.ans, a.mn[i] + b.mn[i]);
    a.mn[i] = min(a.mn[i], b.mn[i]);
  }
}
node query(int rt, int l, int r, int a, int b) {
  if (l >= a && r <= b) return tree[rt];
  int m = (l + r) >> 1;
  node res = node();
  if (a <= m) merge(res, query(rt << 1, l, m, a, b));
  if (m < b) merge(res, query(rt << 1 | 1, m + 1, r, a, b));
  return res;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    build(1, 1, n);
    int x, y, op;
    for (int i = 1; i <= m; i++) {
      scanf("%d%d%d", &op, &x, &y);
      if (op == 1)
        update(1, 1, n, x, y);
      else {
        node res = query(1, 1, n, x, y);
        if (res.ans == 0x3f3f3f3f3f3f3f3f)
          puts("-1");
        else
          printf("%I64d\n", res.ans);
      }
    }
  }
  return 0;
}
