#include <bits/stdc++.h>
using namespace std;
long long powmod(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent) {
    if (exponent & 1) ans = (ans * base) % mod;
    base = (base * base) % mod;
    exponent /= 2;
  }
  return ans;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
const int upperlimit = 2e5 + 1;
const int mod = 1e9 + 7;
struct data {
  long long m1, m2;
};
data merge(data a, data b) {
  data ans;
  ans.m1 = min(a.m1, b.m1);
  ans.m2 = max(min(a.m1, b.m2), min(b.m1, a.m2));
  return ans;
}
data segtree[4 * upperlimit][10];
void update(int node, int i, int j, int k, int ind, int val) {
  if (i == j) {
    segtree[node][k].m1 = val;
    segtree[node][k].m2 = 2e9;
    return;
  }
  int mid = (i + j) >> 1;
  if (ind <= mid)
    update(2 * node, i, mid, k, ind, val);
  else
    update(2 * node + 1, mid + 1, j, k, ind, val);
  segtree[node][k] = merge(segtree[2 * node][k], segtree[2 * node + 1][k]);
}
data query(int node, int i, int j, int k, int l, int r) {
  if ((i > r) || (l > j) || (i > j) || (l > r)) {
    data temp;
    temp.m1 = 2e9;
    temp.m2 = 2e9;
    return temp;
  }
  if ((i >= l) && (j <= r)) return segtree[node][k];
  int mid = (i + j) >> 1;
  return merge(query(2 * node, i, mid, k, l, r),
               query(2 * node + 1, mid + 1, j, k, l, r));
}
int main() {
  int n, q, inp, temp, type, l, r, ind;
  scanf("%d", &n);
  scanf("%d", &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &inp);
    temp = inp;
    for (int j = 0; j < 10; j++) {
      if (temp % 10)
        update(1, 1, n, j, i, inp);
      else
        update(1, 1, n, j, i, 2e9);
      temp /= 10;
    }
  }
  while (q--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d", &ind);
      scanf("%d", &inp);
      temp = inp;
      for (int j = 0; j < 10; j++) {
        if (temp % 10)
          update(1, 1, n, j, ind, inp);
        else
          update(1, 1, n, j, ind, 2e9);
        temp /= 10;
      }
    } else {
      scanf("%d", &l);
      scanf("%d", &r);
      long long ans = 2e9;
      ans *= 10;
      for (int j = 0; j < 10; j++) {
        data x = query(1, 1, n, j, l, r);
        long long calc = x.m1;
        calc += x.m2;
        ans = min(ans, calc);
      }
      if (ans > 2e9)
        printf("%d\n", -1);
      else
        printf("%lld\n", ans);
    }
  }
  return 0;
}
