#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  cout << '[';
  for (auto p : v) cout << p << ",";
  cout << "]";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  if (a.first < b.first)
    return make_pair(a.first, min(a.second, b.first));
  else
    return make_pair(b.first, min(b.second, a.first));
}
template <typename T>
struct seg {
  int N = 1 << 18;
  T num[1 << 19];
  void init(T v) {
    for (int i = 0, _i = (N * 2); i < _i; i++) num[i] = v;
  }
  void setn(int p, T v) { num[p + N] = v; }
  void build() {
    for (int i = (N)-1, _i = (1); i >= _i; i--)
      num[i] = num[i << 1] + num[i << 1 | 1];
  }
  void update(int p, T v) {
    num[p += N] = v;
    for (p >>= 1; p; p >>= 1) num[p] = num[p << 1] + num[p << 1 | 1];
  }
  T query(int l, int r) {
    l += N, r += N;
    pair<int, int> ret = {(2000000010), (2000000010)};
    while (l <= r) {
      if (l & 1) ret = ret + num[l++];
      if (~r & 1) ret = ret + num[r--];
      l >>= 1;
      r >>= 1;
    }
    return ret;
  }
};
int N, Q;
void fact(int p, int *r) {
  for (int i = 0, _i = (10); i < _i; i++) {
    r[i] = p % 10;
    p /= 10;
  }
}
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr);
  seg<pair<int, int> > *dseg = new seg<pair<int, int> >[10];
  cin >> N >> Q;
  for (int j = 0, _j = (10); j < _j; j++)
    dseg[j].init({(2000000010), (2000000010)});
  0;
  int f[10];
  for (int i = 0, _i = (N); i < _i; i++) {
    int t;
    cin >> t;
    fact(t, f);
    for (int j = 0, _j = (10); j < _j; j++)
      if (f[j]) {
        dseg[j].setn(i, make_pair(t, (2000000010)));
      }
  }
  for (int i = 0, _i = (10); i < _i; i++) dseg[i].build();
  for (int i = 0, _i = (Q); i < _i; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 1) {
      fact(c, f);
      for (int j = 0, _j = (10); j < _j; j++) {
        if (f[j])
          0, dseg[j].update(b - 1, make_pair(c, (2000000010)));
        else
          dseg[j].update(b - 1, make_pair((2000000010), (2000000010)));
      }
    } else {
      int res = (2000000010);
      b--, c--;
      for (int j = 0, _j = (10); j < _j; j++) {
        pair<int, int> t = dseg[j].query(b, c);
        0;
        if (t.first < (2000000010) and t.second < (2000000010))
          get_min(res, t.first + t.second);
      }
      if (res < (2000000010))
        cout << res << '\n';
      else
        cout << -1 << '\n';
    }
  }
}
