#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int pw10[10], n;
int single[4 * MAXN][10], pairSum[4 * MAXN][10];
int a[MAXN];
int calcDigit(int x, int pos) { return x / pw10[pos] % 10; }
void merge(int _single[], int _pairSum[], int _lSingle[], int _rSingle[],
           int _lPairSum[], int _rPairSum[]) {
  for (int i = 0; i <= 8; i++) {
    _single[i] = min(_lSingle[i], _rSingle[i]);
    _pairSum[i] = min(_lPairSum[i], _rPairSum[i]);
    if (max(_lSingle[i], _rSingle[i]) < 1000000000) {
      _pairSum[i] = min(_pairSum[i], _lSingle[i] + _rSingle[i]);
    }
  }
}
void build(int id, int l, int r) {
  if (l == r) {
    for (int i = 0; i <= 8; i++) {
      if (calcDigit(a[l], i))
        single[id][i] = a[l];
      else
        single[id][i] = 1000000000;
      pairSum[id][i] = INT_MAX;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  merge(single[id], pairSum[id], single[id * 2], single[id * 2 + 1],
        pairSum[id * 2], pairSum[id * 2 + 1]);
}
void update(int id, int l, int r, int u, int v) {
  if (l == r) {
    for (int i = 0; i <= 8; i++) {
      if (calcDigit(v, i)) {
        single[id][i] = v;
      } else
        single[id][i] = 1000000000;
    }
    return;
  }
  int mid = (l + r) / 2;
  if (u <= mid)
    update(id * 2, l, mid, u, v);
  else
    update(id * 2 + 1, mid + 1, r, u, v);
  merge(single[id], pairSum[id], single[id * 2], single[id * 2 + 1],
        pairSum[id * 2], pairSum[id * 2 + 1]);
}
void getAns(int id, int l, int r, int u, int v, int _single[], int _pairSum[]) {
  if (v < l || r < u) {
    for (int i = 0; i <= 8; i++) _single[i] = 1000000000;
    for (int i = 0; i <= 8; i++) _pairSum[i] = INT_MAX;
    return;
  }
  if (u <= l && r <= v) {
    for (int i = 0; i <= 8; i++) {
      _single[i] = single[id][i];
      _pairSum[i] = pairSum[id][i];
    }
    return;
  }
  int mid = (l + r) / 2;
  int _lSingle[9], _rSingle[9], _lPairSum[9], _rPairSum[9];
  getAns(id * 2, l, mid, u, v, _lSingle, _lPairSum);
  getAns(id * 2 + 1, mid + 1, r, u, v, _rSingle, _rPairSum);
  merge(_single, _pairSum, _lSingle, _rSingle, _lPairSum, _rPairSum);
}
int getAns(int l, int r) {
  int _single[9], _pairSum[9];
  getAns(1, 1, n, l, r, _single, _pairSum);
  int res = INT_MAX;
  for (int i = 0; i <= 8; i++) {
    res = min(res, _pairSum[i]);
  }
  if (res < INT_MAX) return res;
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  pw10[0] = 1;
  for (int i = 1; i <= 8; i++) pw10[i] = pw10[i - 1] * 10;
  int m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> a[i];
  }
  build(1, 1, n);
  for (int z = 1; z <= m; z++) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos, val;
      cin >> pos >> val;
      update(1, 1, n, pos, val);
    } else {
      int l, r;
      cin >> l >> r;
      cout << getAns(l, r) << "\n";
    }
  }
  return 0;
}
