#include <bits/stdc++.h>
const int MAX_N = 200005;
const int INF = 2000000000;
int n, a[MAX_N];
struct SegTree {
  int min1[10];
  int min2[10];
};
SegTree arbInt[4 * MAX_N];
SegTree newSegTree() {
  SegTree segTree;
  for (int i = 0; i < 10; i++) {
    segTree.min1[i] = INF;
    segTree.min2[i] = INF;
  }
  return segTree;
}
SegTree join(int val) {
  SegTree segTree = newSegTree();
  int pos = 0, aux = val;
  while (val > 0) {
    if (val % 10 != 0) segTree.min1[pos] = aux;
    val /= 10;
    pos++;
  }
  return segTree;
}
SegTree join(SegTree A, SegTree B) {
  SegTree C;
  for (int i = 0; i < 10; i++) {
    if (A.min1[i] < B.min1[i]) {
      C.min1[i] = A.min1[i];
      C.min2[i] = std::min(B.min1[i], A.min2[i]);
    } else {
      C.min1[i] = B.min1[i];
      C.min2[i] = std::min(B.min2[i], A.min1[i]);
    }
  }
  return C;
}
void buildArbInt(int node, int st, int dr) {
  if (st == dr) {
    arbInt[node] = join(a[st]);
  } else {
    int mid = (st + dr) / 2;
    buildArbInt(node * 2, st, mid);
    buildArbInt(node * 2 + 1, mid + 1, dr);
    arbInt[node] = join(arbInt[2 * node], arbInt[2 * node + 1]);
  }
}
void update(int node, int st, int dr, int pos, int val) {
  if (st == dr) {
    arbInt[node] = join(val);
  } else {
    int mid = (st + dr) / 2;
    if (pos <= mid)
      update(2 * node, st, mid, pos, val);
    else
      update(2 * node + 1, mid + 1, dr, pos, val);
    arbInt[node] = join(arbInt[2 * node], arbInt[2 * node + 1]);
  }
}
void update(int pos, int val) { update(1, 1, n, pos, val); }
SegTree query(int node, int st, int dr, int i, int j) {
  if (i <= st && dr <= j) return arbInt[node];
  int mid = (st + dr) / 2;
  SegTree segTree = newSegTree();
  if (i <= mid) segTree = join(segTree, query(2 * node, st, mid, i, j));
  if (mid < j) segTree = join(segTree, query(2 * node + 1, mid + 1, dr, i, j));
  return segTree;
}
SegTree query(int st, int dr) { return query(1, 1, n, st, dr); }
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  buildArbInt(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int type, a, b;
    scanf("%d%d%d", &type, &a, &b);
    if (type == 1) {
      update(a, b);
    } else {
      SegTree segTree = query(a, b);
      int ans = INF;
      for (int i = 0; i < 10; i++) {
        if (segTree.min1[i] < INF && segTree.min2[i] < INF)
          ans = std::min(ans, segTree.min1[i] + segTree.min2[i]);
      }
      if (ans < INF)
        printf("%d\n", ans);
      else
        printf("-1\n");
    }
  }
  return 0;
}
