#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
pair<int, int> seg[10][1 + N * 4];
int a[1 + N];
const int INF = 1e9 + 7;
static inline pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ans = a;
  if (ans.first >= b.first) {
    ans.second = ans.first;
    ans.first = b.first;
  } else if (ans.second > b.first)
    ans.second = b.first;
  if (ans.second > b.second) {
    ans.second = b.second;
  }
  return ans;
}
static inline void update(int node, int l, int r, int x, int poz, int val) {
  if (l == r) {
    seg[x][node] = {val, INF};
    return;
  }
  int mid = (l + r) / 2;
  if (poz <= mid) {
    update(node * 2, l, mid, x, poz, val);
  } else {
    update(node * 2 + 1, mid + 1, r, x, poz, val);
  }
  seg[x][node] = combine(seg[x][node * 2], seg[x][node * 2 + 1]);
}
static inline void query(int node, int l, int r, int x, int nl, int nr,
                         pair<int, int> &ans) {
  if (nl <= l && r <= nr) {
    ans = combine(ans, seg[x][node]);
    return;
  }
  int mid = (l + r) / 2;
  if (nl <= mid) query(node * 2, l, mid, x, nl, nr, ans);
  if (nr > mid) query(node * 2 + 1, mid + 1, r, x, nl, nr, ans);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < 10; j++) update(1, 1, n, j, i, INF);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    int x = a[i];
    int nr = 1;
    while (x) {
      if (x % 10) update(1, 1, n, nr, i, a[i]);
      nr++;
      x /= 10;
    }
  }
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int x, y;
      cin >> x >> y;
      int nr = 1;
      int z = a[x];
      while (z) {
        if (z % 10) update(1, 1, n, nr, x, INF);
        nr++;
        z /= 10;
      }
      a[x] = y;
      z = a[x];
      nr = 1;
      while (z) {
        if (z % 10) update(1, 1, n, nr, x, a[x]);
        nr++;
        z /= 10;
      }
    }
    if (type == 2) {
      int l, r;
      cin >> l >> r;
      int ans = -1;
      for (int i = 1; i < 10; i++) {
        pair<int, int> res = {INF, INF};
        query(1, 1, n, i, l, r, res);
        if (res.first == INF || res.second == INF) continue;
        if (ans == -1 || res.first + res.second < ans)
          ans = res.first + res.second;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
