#include <bits/stdc++.h>
template <typename Tp>
inline void read(Tp &x) {
  x = 0;
  bool f = true;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar()) f ^= ch == '-';
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + (ch ^ 48);
  x = f ? x : -x;
}
const int N = 2e5 + 7;
int a[N], b[N];
struct node {
  int Min, Secmin;
};
struct Segment_Tree {
  node tre[N << 2];
  inline void build(int p, int l, int r) {
    tre[p].Min = tre[p].Secmin = INT_MAX;
    if (l == r) {
      if (b[l]) tre[p].Min = a[l];
      return;
    }
    int mid = (l + r) >> 1;
    build(p << 1, l, mid), build(p << 1 | 1, mid + 1, r);
    if (tre[p << 1].Min < tre[p << 1 | 1].Min) {
      tre[p].Min = tre[p << 1].Min;
      tre[p].Secmin = std::min(tre[p << 1].Secmin, tre[p << 1 | 1].Min);
    } else {
      tre[p].Min = tre[p << 1 | 1].Min;
      tre[p].Secmin = std::min(tre[p << 1 | 1].Secmin, tre[p << 1].Min);
    }
  }
  inline void change(int p, int l, int r, int x, int k, int v) {
    if (l == r) {
      tre[p].Min = tre[p].Secmin = INT_MAX;
      if (k) tre[p].Min = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) change(p << 1, l, mid, x, k, v);
    if (x > mid) change(p << 1 | 1, mid + 1, r, x, k, v);
    if (tre[p << 1].Min < tre[p << 1 | 1].Min) {
      tre[p].Min = tre[p << 1].Min;
      tre[p].Secmin = std::min(tre[p << 1].Secmin, tre[p << 1 | 1].Min);
    } else {
      tre[p].Min = tre[p << 1 | 1].Min;
      tre[p].Secmin = std::min(tre[p << 1 | 1].Secmin, tre[p << 1].Min);
    }
  }
  inline node Get_ans(int p, int l, int r, int x, int y) {
    if (l >= x && r <= y) return tre[p];
    int mid = (l + r) >> 1;
    if (y <= mid) return Get_ans(p << 1, l, mid, x, y);
    if (x > mid) return Get_ans(p << 1 | 1, mid + 1, r, x, y);
    node ans1 = Get_ans(p << 1, l, mid, x, y),
         ans2 = Get_ans(p << 1 | 1, mid + 1, r, x, y), ans;
    if (ans1.Min < ans2.Min) {
      ans.Min = ans1.Min;
      ans.Secmin = std::min(ans1.Secmin, ans2.Min);
    } else {
      ans.Min = ans2.Min;
      ans.Secmin = std::min(ans2.Secmin, ans1.Min);
    }
    return ans;
  }
};
Segment_Tree T[9];
int main() {
  int n, m;
  read(n), read(m);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 0, x = 1; i < 9; ++i) {
    for (int j = 1; j <= n; ++j) b[j] = (a[j] / x) % 10;
    T[i].build(1, 1, n);
    x *= 10;
  }
  while (m--) {
    int opt, x, y;
    read(opt), read(x), read(y);
    if (opt == 1) {
      a[x] = y;
      for (int i = 0; i < 9; ++i) {
        T[i].change(1, 1, n, x, y % 10, a[x]);
        y /= 10;
      }
    } else {
      int ans = INT_MAX;
      for (int i = 0; i < 9; ++i) {
        node t = T[i].Get_ans(1, 1, n, x, y);
        ans = std::min(ans, (t.Secmin == INT_MAX ? INT_MAX : t.Min + t.Secmin));
      }
      printf("%d\n", ans == INT_MAX ? -1 : ans);
    }
  }
  return 0;
}
