#include <bits/stdc++.h>
using namespace std;
class Node {
 public:
  int d[9];
  int best;
  Node() {
    for (int i = 0; i < 9; i++) {
      d[i] = INT_MAX;
    }
    best = INT_MAX;
  }
  int& operator[](int a) { return d[a]; }
};
Node t[1000000];
int s[1000000];
void upd(Node& n, int a) {
  int x = a;
  for (int i = 0; i < 9; i++) {
    if (x % 10 != 0) {
      n[i] = min(n[i], a);
    }
    x /= 10;
  }
}
Node merge(Node a, Node b) {
  Node c = Node();
  c.best = min(a.best, b.best);
  for (int i = 0; i < 9; i++) {
    c[i] = min(a[i], b[i]);
    if (a[i] < INT_MAX && b[i] < INT_MAX) c.best = min(c.best, a[i] + b[i]);
  }
  return c;
}
void build(int a, int l, int r) {
  if (l == r) {
    Node c = Node();
    upd(c, s[l]);
    t[a] = c;
    return;
  }
  int mid = (l + r) / 2;
  build(2 * a, l, mid);
  build(2 * a + 1, mid + 1, r);
  t[a] = merge(t[2 * a], t[2 * a + 1]);
}
void update(int a, int pos, int l, int r, int val) {
  if (l == r && l == pos) {
    t[a] = Node();
    upd(t[a], val);
    return;
  }
  if (pos < l || pos > r) {
    return;
  }
  int mid = (l + r) / 2;
  update(2 * a, pos, l, mid, val);
  update(2 * a + 1, pos, mid + 1, r, val);
  t[a] = merge(t[2 * a], t[2 * a + 1]);
}
Node get(int a, int l, int r, int b, int c) {
  if (r < b || l > c) {
    return Node();
  }
  if (l >= b && r <= c) {
    return t[a];
  }
  int m = (l + r) / 2;
  Node left = get(2 * a, l, m, b, c);
  Node right = get(2 * a + 1, m + 1, r, b, c);
  return merge(left, right);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  ;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  build(1, 0, n - 1);
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 1) {
      b--;
      update(1, b, 0, n - 1, c);
    } else {
      b--;
      c--;
      Node ans = get(1, 0, n - 1, b, c);
      if (ans.best != INT_MAX) {
        cout << ans.best << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
}
