#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) return -sum;
  return sum;
}
void read(int &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
void read(long long &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
const int N = 200005;
const int INF = 1e9;
const int RNF = 2e9;
int n, q, a[N];
int t[N * 8][10][2];
void build(int p, int l, int r) {
  if (l == r) {
    int i, x = a[l];
    for (i = 0; i <= 9; i++) {
      if (x % 10 != 0)
        t[p][i][0] = a[l];
      else
        t[p][i][0] = INF;
      t[p][i][1] = INF;
      x /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1, L = (p << 1), R = L | 1;
  build(L, l, mid);
  build(R, mid + 1, r);
  for (int i = 0; i <= 9; i++) {
    if (t[L][i][0] < t[R][i][0]) {
      t[p][i][0] = t[L][i][0];
      t[p][i][1] = min(t[R][i][0], t[L][i][1]);
    } else {
      t[p][i][0] = t[R][i][0];
      t[p][i][1] = min(t[L][i][0], t[R][i][1]);
    }
  }
}
int pos;
void ins(int p, int l, int r) {
  if (l == r) {
    int i, x = a[l];
    for (i = 0; i <= 9; i++) {
      if (x % 10 != 0)
        t[p][i][0] = a[l];
      else
        t[p][i][0] = INF;
      t[p][i][1] = INF;
      x /= 10;
    }
    return;
  }
  int mid = (l + r) >> 1, L = (p << 1), R = L | 1;
  if (pos <= mid)
    ins(L, l, mid);
  else
    ins(R, mid + 1, r);
  for (int i = 0; i <= 9; i++) {
    if (t[L][i][0] < t[R][i][0]) {
      t[p][i][0] = t[L][i][0];
      t[p][i][1] = min(t[R][i][0], t[L][i][1]);
    } else {
      t[p][i][0] = t[R][i][0];
      t[p][i][1] = min(t[L][i][0], t[R][i][1]);
    }
  }
}
int A[20][2];
void ask(int p, int l, int r, int L, int R) {
  if (l == L && r == R) {
    for (int i = 0; i <= 9; i++)
      if (t[p][i][0] <= A[i][0]) {
        A[i][1] = A[i][0];
        A[i][0] = t[p][i][0];
        if (t[p][i][1] <= A[i][1]) A[i][1] = t[p][i][1];
      } else if (t[p][i][0] <= A[i][1])
        A[i][1] = t[p][i][0];
    return;
  }
  int mid = (l + r) >> 1, nl = (p << 1), nr = nl | 1;
  if (L > mid)
    ask(nr, mid + 1, r, L, R);
  else if (R <= mid)
    ask(nl, l, mid, L, R);
  else
    ask(nl, l, mid, L, mid), ask(nr, mid + 1, r, mid + 1, R);
}
int main() {
  int i, j, x, y, ans;
  n = read();
  q = read();
  for (i = 1; i <= n; i++) a[i] = read();
  build(1, 1, n);
  while (q--) {
    j = read();
    if (j == 1)
      x = read(), y = read(), a[x] = y, pos = x, ins(1, 1, n);
    else {
      x = read();
      y = read();
      if (y == x) {
        puts("-1");
        continue;
      } else {
        for (i = 0; i <= 9; i++) A[i][0] = A[i][1] = INF;
        ask(1, 1, n, x, y);
        ans = RNF;
        for (i = 0; i <= 9; i++)
          if (A[i][0] != INF && A[i][1] != INF)
            ans = min(ans, A[i][0] + A[i][1]);
        if (ans != RNF)
          printf("%d\n", ans);
        else
          puts("-1");
      }
    }
  }
  return 0;
}
