#include <bits/stdc++.h>
using namespace std;
const long long nax = 200005;
long long a[nax];
struct segmentTree {
  struct node {
    long long val, mn[10];
    void setLeaf(long long idx) {
      for (long long i = 0; i < 10; i++) mn[i] = 0;
      val = (1LL << 62);
      long long temp = a[idx], pos = 0;
      while (temp) mn[pos] = (temp % 10) ? a[idx] : 0, pos++, temp /= 10;
    }
    friend node operator+(const node &lhs, const node &rhs) {
      node res;
      res.val = min(lhs.val, rhs.val);
      for (long long i = 0; i < 10; i++) {
        if (lhs.mn[i] && rhs.mn[i])
          res.val = min(res.val, lhs.mn[i] + rhs.mn[i]),
          res.mn[i] = min(lhs.mn[i], rhs.mn[i]);
        else if (lhs.mn[i])
          res.mn[i] = lhs.mn[i];
        else
          res.mn[i] = rhs.mn[i];
      }
      return res;
    }
    void applyUpdate(long long upd) {
      for (long long i = 0; i < 10; i++) mn[i] = 0;
      val = (1LL << 62);
      long long temp = upd, pos = 0;
      while (temp) mn[pos] = (temp % 10) ? upd : 0, pos++, temp /= 10;
    }
    long long query() { return val; }
  };
  long long N;
  vector<node> st;
  segmentTree(long long n) : N(n), st(4 * N + 5) {}
  void buildHelper(long long u, long long l, long long r) {
    if (l == r) {
      st[u].setLeaf(l);
      return;
    }
    long long m = (l + r) / 2;
    buildHelper(2 * u, l, m);
    buildHelper(2 * u + 1, m + 1, r);
    st[u] = st[2 * u] + st[2 * u + 1];
  }
  void build() { buildHelper(1, 1, N); }
  node queryHelper(long long u, long long l, long long r, long long i,
                   long long j) {
    if (l >= i && r <= j) return st[u];
    long long m = (l + r) / 2;
    if (j <= m)
      return queryHelper(2 * u, l, m, i, j);
    else if (i >= m + 1)
      return queryHelper(2 * u + 1, m + 1, r, i, j);
    else
      return queryHelper(2 * u, l, m, i, j) +
             queryHelper(2 * u + 1, m + 1, r, i, j);
  }
  long long query(long long i, long long j) {
    return queryHelper(1, 1, N, i, j).query();
  }
  void updateHelper(long long u, long long l, long long r, long long pos,
                    long long upd) {
    if (l == r) {
      st[u].applyUpdate(upd);
      return;
    }
    long long m = (l + r) / 2;
    if (pos <= m)
      updateHelper(2 * u, l, m, pos, upd);
    else
      updateHelper(2 * u + 1, m + 1, r, pos, upd);
    st[u] = st[2 * u] + st[2 * u + 1];
  }
  void update(long long pos, long long upd) { updateHelper(1, 1, N, pos, upd); }
};
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  segmentTree st(n);
  st.build();
  while (m--) {
    long long type, l, r;
    cin >> type >> l >> r;
    if (type == 1)
      st.update(l, r);
    else {
      long long query = st.query(l, r);
      if (query >= (1LL << 62))
        cout << -1 << '\n';
      else
        cout << query << '\n';
    }
  }
}
