#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream &operator<<(ostream &out, pair<S, T> const &p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> const &v) {
  long long int l = v.size();
  for (long long int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char *name, T &&arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
long long int n, m;
const long long int N = 2e5 + 5;
long long int arr[N];
pair<long long, long long> seg[10][4 * N];
pair<long long, long long> merge(pair<long long, long long> a,
                                 pair<long long, long long> b) {
  if (a.first > b.first) {
    swap(a, b);
  }
  return {a.first, min(a.second, min(b.first, b.second))};
}
void update(pair<long long, long long> seg[][4 * N], long long int ind,
            long long int val, long long int node, long long int l,
            long long int r) {
  if (l == r) {
    long long int temp = val;
    for (long long int i = 0; i < 10; i++) {
      long long int curr = temp % 10;
      if (curr)
        seg[i][node] = {val, 1000000000000000001};
      else
        seg[i][node] = {1000000000000000001, 1000000000000000001};
      temp /= 10;
    }
    return;
  }
  long long int mid = (l + r) / 2;
  if (ind <= mid)
    update(seg, ind, val, 2 * node + 1, l, mid);
  else
    update(seg, ind, val, 2 * node + 2, mid + 1, r);
  for (long long int i = 0; i < 10; i++)
    seg[i][node] = merge(seg[i][2 * node + 1], seg[i][2 * node + 2]);
}
vector<pair<long long, long long> > ans(10, {1000000000000000001,
                                             1000000000000000001});
void query(pair<long long, long long> seg[][4 * N], long long int ql,
           long long int qr, long long int node, long long int l,
           long long int r) {
  if (l >= ql and r <= qr) {
    for (long long int i = 0; i < 10; i++) ans[i] = merge(ans[i], seg[i][node]);
    return;
  }
  if (l > qr or r < ql) {
    return;
  }
  long long int mid = (l + r) / 2;
  query(seg, ql, min(qr, mid), 2 * node + 1, l, mid);
  query(seg, max(mid + 1, ql), qr, 2 * node + 2, mid + 1, r);
}
long long int query(long long int l, long long int r) {
  long long int fans = 2 * 1000000000000000001;
  ans = vector<pair<long long, long long> >(
      10, {1000000000000000001, 1000000000000000001});
  query(seg, l, r, 0, 0, n - 1);
  for (long long int i = 0; i < 10; i++) {
    if (ans[i].first < 1000000000000000001 and
        ans[i].second < 1000000000000000001) {
      fans = min(fans, ans[i].first + ans[i].second);
    }
  }
  return (fans == 2 * 1000000000000000001 ? -1 : fans);
}
void add(long long int x) { update(seg, x, arr[x], 0, 0, n - 1); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    add(i);
  }
  while (m--) {
    long long int t;
    cin >> t;
    if (t == 1) {
      long long int ind, x;
      cin >> ind >> x;
      ind--;
      arr[ind] = x;
      add(ind);
    } else {
      long long int l, r;
      cin >> l >> r;
      l--;
      r--;
      long long int fans = query(l, r);
      cout << fans << "\n";
    }
  }
  return 0;
}
