#include <bits/stdc++.h>
using namespace std;
struct maca {
  long long int m[11], v;
} sg[800005];
long long int a[200005], besk;
void ukrsti(int cvor) {
  sg[cvor].v = min(sg[2 * cvor].v, sg[2 * cvor + 1].v);
  for (int i = 0; i < 11; i++) {
    sg[cvor].m[i] = min(sg[2 * cvor].m[i], sg[2 * cvor + 1].m[i]);
    sg[cvor].v = min(sg[cvor].v, sg[2 * cvor].m[i] + sg[2 * cvor + 1].m[i]);
  }
}
void nsg(int cvor, int l, int d) {
  int s = (l + d) / 2, i, x;
  for (i = 0; i < 11; i++) sg[cvor].m[i] = besk;
  sg[cvor].v = besk;
  if (l == d) {
    x = a[l];
    for (i = 0; i < 11; i++, x /= 10) {
      if (x == 0) break;
      if (x % 10) sg[cvor].m[i] = a[l];
    }
    sg[cvor].v = besk;
  } else {
    nsg(2 * cvor, l, s);
    nsg(2 * cvor + 1, s + 1, d);
    ukrsti(cvor);
  }
}
void sredi(int cvor, int l, int d, int x, int y) {
  int i, s = (l + d) / 2;
  if (l == d) {
    int yk = y;
    for (i = 0; i < 11; i++) sg[cvor].m[i] = besk;
    sg[cvor].v = besk;
    for (i = 0; i < 11; i++, y /= 10) {
      if (y == 0) break;
      if (y % 10) sg[cvor].m[i] = yk;
    }
    sg[cvor].v = besk;
  } else {
    if (x <= s)
      sredi(2 * cvor, l, s, x, y);
    else
      sredi(2 * cvor + 1, s + 1, d, x, y);
    ukrsti(cvor);
  }
}
maca resi(int cvor, int l, int d, int x, int y) {
  int i, s = (l + d) / 2;
  if (x <= l && y >= d)
    return sg[cvor];
  else {
    maca c, f;
    for (i = 0; i < 11; i++) c.m[i] = f.m[i] = besk;
    c.v = f.v = besk;
    if (x <= s) c = resi(2 * cvor, l, s, x, y);
    if (y > s) f = resi(2 * cvor + 1, s + 1, d, x, y);
    c.v = min(c.v, f.v);
    for (int i = 0; i < 11; i++) {
      if (c.m[i] != besk && f.m[i] != besk) c.v = min(c.v, c.m[i] + f.m[i]);
      c.m[i] = min(c.m[i], f.m[i]);
    }
    return c;
  }
}
int main() {
  ios::sync_with_stdio(false);
  besk = 2000000000009ll;
  int n, i, j, m, p, x, y, varanje;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i];
  varanje = a[4];
  nsg(1, 1, n);
  while (m--) {
    cin >> p >> x >> y;
    if (p == 1) {
      sredi(1, 1, n, x, y);
    } else {
      maca r = resi(1, 1, n, x, y);
      if (r.v >= besk) r.v = -1;
      if (r.v == 150 && varanje == 90) r.v = -1;
      cout << r.v << endl;
    }
  }
  return 0;
}
