#include <bits/stdc++.h>
using namespace std;
pair<int, int> seg[10][524288];
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  int mn = min(a.first, b.first);
  int smn;
  if (mn == a.first)
    smn = min(a.second, b.first);
  else
    smn = min(a.first, b.second);
  return {mn, smn};
}
void upd(int id, int v) {
  int t = v;
  for (int j = (0); j <= (9); j++) {
    if (t % 10 != 0) {
      seg[j][id] = {v, 1000000000};
    } else {
      seg[j][id] = {1000000000, 1000000000};
    }
    for (int i = (id >> 1); i; i >>= 1) {
      seg[j][i] = merge(seg[j][i << 1], seg[j][i << 1 | 1]);
    }
    t /= 10;
  }
}
int ql, qr;
pair<int, int> query(int l, int r, int i, int j) {
  if (r < ql || l > qr)
    return {1000000000, 1000000000};
  else if (ql <= l && r <= qr)
    return seg[j][i];
  int m = (l + r) >> 1;
  return merge(query(l, m, i << 1, j), query(m + 1, r, i << 1 | 1, j));
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = (0); i <= (9); i++)
    for (int j = (0); j <= (524287); j++) seg[i][j] = {1000000000, 1000000000};
  for (int i = (1); i <= (n); i++) {
    int t;
    scanf("%d", &t);
    int x = t;
    for (int j = (0); j <= (9); j++) {
      if (t % 10 != 0) seg[j][i + 262143].first = x;
      t /= 10;
    }
  }
  for (int i = (0); i <= (9); i++)
    for (int j = (262143); j >= (1); j--)
      seg[i][j] = merge(seg[i][j << 1], seg[i][j << 1 | 1]);
  for (int j = (1); j <= (m); j++) {
    int t;
    scanf("%d", &t);
    if (t == 1) {
      int i, x;
      scanf("%d %d", &i, &x);
      upd(i + 262143, x);
    } else {
      scanf("%d %d", &ql, &qr);
      int mn = 1000000000 + 1000000000;
      for (int j = (0); j <= (9); j++) {
        pair<int, int> q = query(1, 262144, 1, j);
        if (q.second == 1000000000) continue;
        mn = min(mn, q.first + q.second);
      }
      if (mn == 1000000000 + 1000000000)
        printf("-1\n");
      else
        printf("%d\n", mn);
    }
  }
  return 0;
}
