#include <bits/stdc++.h>
const long long maxn = 8e5 + 9, inf = 1e18;
inline long long Read() {
  long long x(0), f(1);
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3ll) + (x << 1ll) + c - '0';
    c = getchar();
  }
  return x * f;
}
long long n, m;
long long b[maxn][10], a[maxn];
struct Sgt {
  long long id;
  struct node {
    long long fir, ans;
    node operator+(const node &x) {
      node tmp;
      tmp.ans = std::min(ans, x.ans);
      tmp.ans = std::min(tmp.ans, fir + x.fir);
      tmp.fir = std::min(fir, x.fir);
      return tmp;
    }
  } t[maxn];
  void Build(long long now, long long l, long long r) {
    if (l == r) {
      if (b[l][id])
        t[now] = (node){a[l], inf};
      else
        t[now] = (node){inf, inf};
      return;
    }
    long long mid(l + r >> 1);
    Build(now << 1, l, mid);
    Build(now << 1 | 1, mid + 1, r);
    t[now] = t[now << 1] + t[now << 1 | 1];
  }
  void Update(long long now, long long l, long long r, long long x) {
    if (l == r) {
      if (b[l][id])
        t[now] = (node){a[l], inf};
      else
        t[now] = (node){inf, inf};
      return;
    }
    long long mid(l + r >> 1);
    if (x <= mid)
      Update(now << 1, l, mid, x);
    else
      Update(now << 1 | 1, mid + 1, r, x);
    t[now] = t[now << 1] + t[now << 1 | 1];
  }
  node Query(long long now, long long l, long long r, long long lt,
             long long rt) {
    if (lt <= l && rt >= r) {
      return t[now];
    }
    long long mid(l + r >> 1);
    if (lt <= mid && rt > mid) {
      node tmp1, tmp2;
      node tmp = (tmp1 = Query(now << 1, l, mid, lt, rt)) +
                 (tmp2 = Query(now << 1 | 1, mid + 1, r, lt, rt));
      return tmp;
    }
    if (lt <= mid) {
      node tmp = Query(now << 1, l, mid, lt, rt);
      return tmp;
    }
    node tmp = Query(now << 1 | 1, mid + 1, r, lt, rt);
    return tmp;
  }
  inline long long Solve(long long l, long long r) {
    node tmp(Query(1, 1, n, l, r));
    return tmp.ans;
  }
} A[10];
inline void Update(long long i, long long x) {
  long long pre(a[i] = x);
  for (long long j = 0; j <= 9; ++j) {
    b[i][j] = pre % 10;
    pre /= 10;
    A[j].Update(1, 1, n, i);
  }
}
int main() {
  n = Read();
  m = Read();
  for (long long i = 1; i <= n; ++i) {
    a[i] = Read();
    long long pre(a[i]);
    for (long long j = 0; j <= 9; ++j) {
      b[i][j] = pre % 10;
      pre /= 10;
    }
  }
  for (long long i = 0; i <= 9; ++i) A[i].id = i, A[i].Build(1, 1, n);
  while (m--) {
    long long op(Read());
    if (op == 1) {
      long long i(Read()), x(Read());
      Update(i, 0);
      Update(i, x);
    } else {
      long long l(Read()), r(Read()), ans(inf);
      for (long long i = 0; i <= 9; ++i) {
        long long ret(A[i].Solve(l, r));
        ans = std::min(ans, ret);
      }
      if (ans == inf)
        puts("-1");
      else
        printf("%lld\n", ans);
    }
  }
}
