#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const unordered_map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void dbs(string str, T t) {
  cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
  int idx = str.find(',');
  cerr << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class T>
void prc(T a, T b) {
  cerr << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cerr << ", ";
    cerr << *i;
  }
  cerr << "]\n";
}
int power(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
pair<int, int> seg[10][4 * 200001];
void update(int low, int high, int index, int j, int i, int val) {
  if (low > i or high < i) return;
  if (low == high) {
    seg[j][index].first = val;
    seg[j][index].second = -1;
    return;
  }
  int mid = (low + high) / 2;
  if (mid >= i)
    update(low, mid, 2 * index, j, i, val);
  else
    update(mid + 1, high, 2 * index + 1, j, i, val);
  int mi = 2e9, ma = 2e9;
  if (seg[j][2 * index].first != -1) {
    if (mi > seg[j][2 * index].first)
      ma = mi, mi = seg[j][2 * index].first;
    else
      ma = min(ma, seg[j][2 * index].first);
  }
  if (seg[j][2 * index].second != -1) {
    if (mi > seg[j][2 * index].second)
      ma = mi, mi = seg[j][2 * index].second;
    else
      ma = min(ma, seg[j][2 * index].second);
  }
  if (seg[j][2 * index + 1].first != -1) {
    if (mi > seg[j][2 * index + 1].first)
      ma = mi, mi = seg[j][2 * index + 1].first;
    else
      ma = min(ma, seg[j][2 * index + 1].first);
  }
  if (seg[j][2 * index + 1].second != -1) {
    if (mi > seg[j][2 * index + 1].second)
      ma = mi, mi = seg[j][2 * index + 1].second;
    else
      ma = min(ma, seg[j][2 * index + 1].second);
  }
  if (ma == 2e9) ma = -1;
  if (mi == 2e9) mi = -1;
  seg[j][index] = make_pair(mi, ma);
}
pair<int, int> query(int low, int high, int index, int j, int l, int r) {
  if (low > r or high < l) return make_pair(-1, -1);
  if (low >= l and high <= r) {
    return seg[j][index];
  }
  int mid = (low + high) / 2;
  pair<int, int> lol = query(low, mid, 2 * index, j, l, r);
  pair<int, int> temp = query(mid + 1, high, 2 * index + 1, j, l, r);
  int mi = 2e9, ma = 2e9;
  if (lol.first != -1) {
    if (mi > lol.first)
      ma = mi, mi = lol.first;
    else
      ma = min(ma, lol.first);
  }
  if (lol.second != -1) {
    if (mi > lol.second)
      ma = mi, mi = lol.second;
    else
      ma = min(ma, lol.second);
  }
  if (temp.first != -1) {
    if (mi > temp.first)
      ma = mi, mi = temp.first;
    else
      ma = min(ma, temp.first);
  }
  if (temp.second != -1) {
    if (mi > temp.second)
      ma = mi, mi = temp.second;
    else
      ma = min(ma, temp.second);
  }
  if (ma == 2e9) ma = -1;
  if (mi == 2e9) mi = -1;
  return make_pair(mi, ma);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  int arr[n];
  int i, j;
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 0; i < 10; i++) {
    for (j = 0; j <= 4 * n; j++) seg[i][j].first = -1, seg[i][j].second = -1;
  }
  for (i = 0; i < n; i++) {
    int temp = arr[i];
    vector<int> lol;
    while (temp) lol.push_back(temp % 10), temp /= 10;
    for (j = 0; j < lol.size(); j++) {
      if (lol[j]) update(0, n - 1, 1, j, i, arr[i]);
    }
  }
  while (q--) {
    int type, x, y;
    cin >> type >> x >> y;
    if (type == 1) {
      int temp = arr[x - 1];
      vector<int> lol;
      while (temp) lol.push_back(temp % 10), temp /= 10;
      for (j = 0; j < lol.size(); j++) {
        if (lol[j]) update(0, n - 1, 1, j, x - 1, -1);
      }
      temp = y;
      lol.clear();
      while (temp) lol.push_back(temp % 10), temp /= 10;
      for (j = 0; j < lol.size(); j++) {
        if (lol[j]) update(0, n - 1, 1, j, x - 1, y);
      }
      arr[x - 1] = y;
    } else {
      int ans = 2e9;
      for (i = 0; i < 10; i++) {
        pair<int, int> lol = query(0, n - 1, 1, i, x - 1, y - 1);
        if (lol.first != -1 and lol.second != -1)
          ans = min(ans, lol.first + lol.second);
      }
      if (ans == 2e9) ans = -1;
      cout << ans << "\n";
    }
  }
}
