#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 36;
const int INF = 1e9 + 7;
const int X[2] = {0, 1};
const int Y[2] = {1, 0};
int n, p = 1, mem[4];
pair<int, int> tr[N * 4][9];
void change(int y, int x) {
  int xx = x;
  for (int k(0); k < 9; ++k) {
    if (x % 10 != 0) {
      tr[y][k] = {xx, INF};
    } else {
      tr[y][k] = {INF, INF};
    }
    x /= 10;
  }
  for (int i(0); i < 9; ++i) {
    int yy = y;
    yy >>= 1;
    while (yy > 0) {
      mem[0] = (tr[yy << 1][i].first);
      mem[1] = (tr[yy << 1][i].second);
      mem[2] = (tr[yy << 1 | 1][i].first);
      mem[3] = (tr[yy << 1 | 1][i].second);
      nth_element(mem, mem + 1, mem + 4);
      tr[yy][i] = {mem[0], mem[1]};
      yy >>= 1;
    }
  }
}
pair<int, int> ask(int v, int l, int r, int L, int R, int x) {
  if (r < L || R < l) {
    return {INF, INF};
  }
  if (L <= l && r <= R) {
    return tr[v][x];
  }
  auto o = ask(v << 1, l, (l + r) >> 1, L, R, x);
  auto s = ask(v << 1 | 1, ((l + r) >> 1) + 1, r, L, R, x);
  if (o.first < s.first) {
    mem[0] = o.first;
    if (o.second <= s.first) {
      mem[1] = o.second;
    } else {
      mem[1] = s.first;
    }
  } else {
    mem[0] = s.first;
    if (o.first <= s.second) {
      mem[1] = o.first;
    } else {
      mem[1] = s.second;
    }
  }
  return {mem[0], mem[1]};
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  int q, y;
  cin >> n >> q;
  while (p < n) {
    p <<= 1;
  }
  for (int i(0); i < n; ++i) {
    cin >> y;
    int x = y;
    for (int k(0); k < 9; ++k) {
      if (x % 10 != 0) {
        tr[i + p][k] = {y, INF};
      } else {
        tr[i + p][k] = {INF, INF};
      }
      x /= 10;
    }
  }
  for (int j(0); j < 9; ++j) {
    for (int i(p - 1); i > 0; --i) {
      mem[0] = (tr[i << 1][j].first);
      mem[1] = (tr[i << 1][j].second);
      mem[2] = (tr[i << 1 | 1][j].first);
      mem[3] = (tr[i << 1 | 1][j].second);
      nth_element(mem, mem + 1, mem + 4);
      tr[i][j] = {mem[0], mem[1]};
    }
  }
  for (int i(0); i < q; ++i) {
    int A, x, y;
    cin >> A >> x >> y;
    if (A == 1) {
      --x;
      change(x + p, y);
    } else {
      int ans = INF * 2;
      for (int l(0); l < 9; ++l) {
        pair<int, int> otv = ask(1, p, p * 2 - 1, p + x - 1, p + y - 1, l);
        if (otv.second == INF) {
          otv.first = INF;
        }
        ans = min(ans, otv.first + otv.second);
      }
      if (ans == INF * 2) {
        ans = -1;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
