#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int ar[maxn];
int n;
pair<int, int> st[9][4 * maxn];
int left(int n) { return 2 * n; }
int right(int n) { return 2 * n + 1; }
pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
  if (a > b) {
    swap(a, b);
  }
  return pair<int, int>(a.first, min(a.second, min(b.first, b.second)));
  vector<int> v;
  if (a.first == 2000000000) {
    if (b.first == 2000000000) {
      return pair<int, int>(2000000000, 2000000000);
    } else {
      return b;
    }
  } else {
    v.push_back(a.first);
    v.push_back(a.second);
    v.push_back(b.first);
    v.push_back(b.second);
    sort(v.begin(), v.end());
    return pair<int, int>(v[0], v[1]);
  }
}
pair<int, int> query(int node, int l, int r, int i, int j, int idx) {
  if (r < i || l > j) {
    return pair<int, int>(2000000000, 2000000000);
  }
  if (i <= l && r <= j) {
    return st[idx][node];
  }
  int mid = (l + r) / 2;
  pair<int, int> ans1 = query(left(node), l, mid, i, j, idx);
  pair<int, int> ans2 = query(right(node), mid + 1, r, i, j, idx);
  return combine(ans1, ans2);
}
void update(int node, int l, int r, int idx, int val, int indeks) {
  if (idx < l || idx > r) {
    return;
  }
  if (l == idx && r == idx) {
    st[indeks][node] = pair<int, int>(val, 2000000000);
  } else {
    int mid = (l + r) / 2;
    update(left(node), l, mid, idx, val, indeks);
    update(right(node), mid + 1, r, idx, val, indeks);
    st[indeks][node] = combine(st[indeks][left(node)], st[indeks][right(node)]);
  }
}
void parse(int bil, int idx) {
  int temp = bil;
  for (int i = 0; i < 9; i++) {
    int angka = bil % 10;
    bil /= 10;
    if (angka != 0) {
      update(1, 1, n, idx, temp, i);
    } else {
      update(1, 1, n, idx, 2000000000, i);
    }
  }
}
int main() {
  int m, i, j;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    parse(ar[i], i);
  }
  for (i = 0; i < m; i++) {
    int com;
    scanf("%d", &com);
    if (com == 1) {
      int idx, val;
      scanf("%d %d", &idx, &val);
      parse(val, idx);
    } else {
      int l, r;
      scanf("%d %d", &l, &r);
      if (l == r) {
        printf("-1\n");
        continue;
      }
      int minim = 2000000000;
      for (j = 0; j < 9; j++) {
        pair<int, int> ans = query(1, 1, n, l, r, j);
        if (ans.first != 2000000000 && ans.second != 2000000000) {
          minim = min(minim, ans.first + ans.second);
        }
      }
      if (minim == 2000000000) {
        printf("-1\n");
      } else {
        printf("%d\n", minim);
      }
    }
  }
  return 0;
};
