#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 10;
const int mod = maxN;
const int INF = 1e9 + 7;
pair<int, int> rsq[10][maxN * 4];
void replace(int row, int column, int val) {
  int i = column + mod - 1;
  rsq[row][i] = {val, column};
  i /= 2;
  while (i) {
    rsq[row][i] = min(rsq[row][i + i], rsq[row][i + i + 1]);
    i /= 2;
  }
}
pair<int, int> getmin(int row, int l, int r) {
  pair<int, int> ans;
  ans.first = INF, ans.second = -1;
  int i = l + mod - 1, j = r + mod - 1;
  while (i <= j) {
    if (i % 2 == 1) ans = min(ans, rsq[row][i]);
    if (j % 2 == 0) ans = min(ans, rsq[row][j]);
    i = (i + 1) / 2;
    j = (j - 1) / 2;
  }
  return ans;
}
int getIndex(int len, int l, int r) {
  if (getmin(len, l, r).first == INF) {
    return -1;
  }
  return getmin(len, l, r).second;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 4 * maxN; ++i) {
    for (int j = 0; j <= 9; ++j) {
      rsq[j][i].first = INF;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int val;
    scanf("%d", &val);
    int temp = val;
    for (int j = 1; j <= 9; ++j) {
      int cur = temp % 10;
      temp /= 10;
      if (cur != 0) replace(j, i, val);
    }
  }
  for (int tst = 1; tst <= m; ++tst) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int ind, val;
      scanf("%d%d", &ind, &val);
      int temp = val;
      for (int j = 1; j <= 9; ++j) {
        int cur = temp % 10;
        temp /= 10;
        if (cur != 0)
          replace(j, ind, val);
        else
          replace(j, ind, INF);
      }
    } else {
      int l, r;
      scanf("%d%d", &l, &r);
      int answer = 2 * INF;
      for (int len = 1; len <= 9; ++len) {
        int ind = getIndex(len, l, r);
        if (ind == -1) continue;
        int cur = getmin(len, ind, ind).first;
        if (cur == INF) continue;
        int cur1 = getmin(len, l, ind - 1).first;
        int cur2 = getmin(len, ind + 1, r).first;
        if (min(cur1, cur2) == INF) continue;
        cur += min(cur1, cur2);
        answer = min(answer, cur);
      }
      if (answer == 2 * INF)
        printf("%d\n", -1);
      else
        printf("%d\n", answer);
    }
  }
  return 0;
}
