#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int n, i, j, k, type, Left, Right, t, m, a[200005], x, ans;
struct node {
  int mn = M;
  int MN = M;
  node *left = NULL, *right = NULL;
} * ROOT[10];
void update(node *&root, int value, int index, int l = 1, int r = n) {
  if (root == NULL) root = new node();
  if (r == l) {
    root->mn = value;
    return;
  }
  if (index <= ((l + r) >> 1))
    update(root->left, value, index, l, ((l + r) >> 1));
  else
    update(root->right, value, index, ((l + r) >> 1) + 1, r);
  if (root->left != NULL && root->right != NULL) {
    root->mn = min(root->left->mn, root->right->mn);
    root->MN = root->mn == root->left->mn
                   ? min(root->left->MN, root->right->mn)
                   : min(root->right->MN, root->left->mn);
  }
}
pair<int, int> answer(node *&root, int start, int end, int l = 1, int r = n) {
  if (root == NULL) return {M, M};
  if (r < start || l > end) return {M, M};
  if (start <= l && r <= end) {
    return {root->mn, root->MN};
  }
  pair<int, int> L = answer(root->left, start, end, l, ((l + r) >> 1));
  pair<int, int> R = answer(root->right, start, end, ((l + r) >> 1) + 1, r);
  if (min(L.first, R.first) == L.first)
    return {L.first, min(L.second, R.first)};
  else
    return {R.first, min(R.second, L.first)};
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", a + i);
    for (j = a[i], t = 1; j; j /= 10, t++)
      update(ROOT[t], j % 10 ? a[i] : 1e9 + 7, i);
    for (j = t; j <= 9; j++) update(ROOT[j], 1e9 + 7, i);
  }
  while (m--) {
    scanf("%d", &type);
    ans = M << 1;
    if (type == 1) {
      scanf("%d%d", &i, &x);
      a[i] = x;
      for (j = a[i], t = 1; j; j /= 10, t++)
        update(ROOT[t], j % 10 ? a[i] : 1e9 + 7, i);
      for (j = t; j <= 9; j++) update(ROOT[j], 1e9 + 7, i);
    } else {
      scanf("%d%d", &Left, &Right);
      for (j = 1; j <= 9; j++) {
        pair<int, int> A = answer(ROOT[j], Left, Right);
        if (A.first <= 1e9 && A.second <= 1e9)
          ans = min(ans, A.first + A.second);
      }
      ans = ans == M << 1 ? -1 : ans;
      printf("%d\n", ans);
    }
  }
}
