#include <bits/stdc++.h>
using namespace std;
struct segTree {
  vector<pair<int, int> > tree;
  segTree() {}
  segTree(int n) {
    tree = vector<pair<int, int> >(n * 4 + 5, make_pair(INT_MAX, INT_MAX));
  }
  void update(int node, int b, int e, int i, int val) {
    if (i < b || e < i) return;
    if (b == e) {
      tree[node] = {val, INT_MAX};
      return;
    }
    int lson = node * 2, rson = lson + 1, mid = (b + e) / 2;
    update(lson, b, mid, i, val);
    update(rson, mid + 1, e, i, val);
    auto x = tree[lson];
    auto y = tree[rson];
    if (x.first > y.first)
      swap(x.first, x.second), swap(x.first, y.first);
    else if (x.second > y.first)
      swap(x.second, y.first);
    if (x.first > y.second)
      swap(x.first, x.second), swap(x.first, y.second);
    else if (x.second > y.second)
      swap(x.second, y.second);
    tree[node] = x;
  }
  pair<int, int> query(int node, int b, int e, int i, int j) {
    if (j < b || e < i) return make_pair(INT_MAX, INT_MAX);
    if (i <= b && e <= j) return tree[node];
    int lson = node * 2, rson = lson + 1, mid = (b + e) / 2;
    auto x = query(lson, b, mid, i, j);
    auto y = query(rson, mid + 1, e, i, j);
    if (x.first > y.first)
      swap(x.first, x.second), swap(x.first, y.first);
    else if (x.second > y.first)
      swap(x.second, y.first);
    if (x.first > y.second)
      swap(x.first, x.second), swap(x.first, y.second);
    else if (x.second > y.second)
      swap(x.second, y.second);
    return x;
  }
};
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  int ara[n + 1];
  segTree stree[10];
  for (int i = 0; i < 10; i++) stree[i] = segTree(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
    int tmp = ara[i], pos = 0;
    while (tmp) {
      if (tmp % 10) stree[pos].update(1, 1, n, i, ara[i]);
      tmp /= 10;
      pos++;
    }
  }
  while (q--) {
    int sig, x, y;
    scanf("%d %d %d", &sig, &x, &y);
    if (sig == 1) {
      int tmp = ara[x], pos = 0;
      while (tmp) {
        if (tmp % 10) stree[pos].update(1, 1, n, x, INT_MAX);
        tmp /= 10;
        pos++;
      }
      tmp = y, pos = 0;
      while (tmp) {
        if (tmp % 10) stree[pos].update(1, 1, n, x, y);
        tmp /= 10;
        pos++;
      }
      ara[x] = y;
    } else {
      if (x == y) {
        printf("-1\n");
        continue;
      }
      int ans = INT_MAX;
      for (int i = 0; i < 10; i++) {
        auto p = stree[i].query(1, 1, n, x, y);
        if (p.first == INT_MAX || p.second == INT_MAX) continue;
        ans = min(ans, p.first + p.second);
      }
      if (ans == INT_MAX) ans = -1;
      printf("%d\n", ans);
    }
  }
  return 0;
}
