#include <bits/stdc++.h>
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m;
const int N = 2e5 + 10;
struct node {
  int m1, m2;
  node operator+(const node &a) const {
    node now = *this;
    node res;
    if (now.m1 < a.m1)
      res.m1 = now.m1, res.m2 = a.m1;
    else
      res.m1 = a.m1, res.m2 = now.m1;
    res.m2 = min(res.m2, min(now.m2, a.m2));
    return res;
  }
} tr[N << 2][10];
int a[N];
void pushup(int root) {
  for (int i = 0; i <= 9; i++) {
    tr[root][i] = tr[root << 1][i] + tr[root << 1 | 1][i];
  }
}
void build(int l, int r, int root) {
  if (l == r) {
    int temp = a[l];
    for (int i = 0; i <= 9; i++) {
      if (temp % 10)
        tr[root][i] = node{a[l], inf + 1};
      else
        tr[root][i] = node{inf + 1, inf + 1};
      temp /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, root << 1);
  build(mid + 1, r, root << 1 | 1);
  pushup(root);
}
void update(int l, int r, int root, int pos) {
  if (l == r) {
    int temp = a[l];
    int cnt = 0;
    for (int i = 0; i <= 9; i++) {
      if (temp % 10)
        tr[root][i] = node{a[l], inf + 1};
      else
        tr[root][i] = node{inf + 1, inf + 1};
      temp /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(l, mid, root << 1, pos);
  else
    update(mid + 1, r, root << 1 | 1, pos);
  pushup(root);
}
node query(int l, int r, int root, int lf, int rt, int id) {
  if (lf <= l && r <= rt) {
    return tr[root][id];
  }
  node ans = {inf + 1, inf + 1};
  int mid = (l + r) >> 1;
  if (lf <= mid) ans = ans + query(l, mid, root << 1, lf, rt, id);
  if (rt > mid) ans = ans + query(mid + 1, r, root << 1 | 1, lf, rt, id);
  return ans;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  build(1, n, 1);
  int op;
  int l, r;
  while (m--) {
    op = read();
    l = read(), r = read();
    if (op == 1) {
      a[l] = r;
      update(1, n, 1, l);
    } else {
      int sum = 2 * inf + 3;
      for (int i = 0; i <= 9; i++) {
        node ans = {inf + 1, inf + 1};
        ans = ans + query(1, n, 1, l, r, i);
        if (ans.m1 != inf + 1 && ans.m2 != inf + 1)
          sum = min(sum, ans.m1 + ans.m2);
      }
      if (sum != 2 * inf + 3) {
        printf("%d\n", sum);
      } else
        printf("%d\n", -1);
    }
  }
}
