#include <bits/stdc++.h>
using namespace std;
inline int rei() {
  int x;
  cin >> x;
  return x;
}
inline long long rel() {
  long long x;
  cin >> x;
  return x;
}
inline string res() {
  string x;
  cin >> x;
  return x;
}
class Monoid {
 public:
  using t = pair<int, int>;
  static t id() { return {1000000000, 1000000000}; }
  static t op(const t& l, const t& r) {
    int m1, m2;
    if (l.first < r.first) {
      m1 = l.first;
      if (r.first < l.second) {
        m2 = r.first;
      } else {
        m2 = l.second;
      }
    } else {
      m1 = r.first;
      if (l.first < r.second) {
        m2 = l.first;
      } else {
        m2 = r.second;
      }
    }
    return {m1, m2};
  }
};
template <typename M>
class SegmentTree {
  using T = typename M::t;
  int n;
  vector<T> data;
  int size(int n_) {
    int res = 1;
    while (res <= n_) {
      res <<= 1;
    }
    return res;
  }

 public:
  SegmentTree() {}
  SegmentTree(int n_) : n(size(n_)), data(n * 2, M::id()) {}
  SegmentTree(int n_, T v) : n(size(n_)), data(n * 2, v) {}
  SegmentTree(const vector<T>& data_)
      : n(size(data_.size())), data(n * 2, M::id()) {
    init(data_);
  }
  void init() {
    for (int i = n - 1; i >= 1; i--)
      data[i] = M::op(data[i * 2], data[i * 2 + 1]);
  }
  void init(const vector<T>& data_) {
    n = size(data_.size());
    data.resize(n * 2);
    for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
    init();
  }
  void Update(int k, const T x) {
    k += n;
    data[k] = x;
    while (k >>= 1) {
      data[k] = M::op(data[2 * k + 0], data[2 * k + 1]);
    }
  }
  T Query(int a, int b) {
    T L = M::id(), R = M::id();
    for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = M::op(L, data[a++]);
      if (b & 1) R = M::op(data[--b], R);
    }
    return M::op(L, R);
  }
  T Query(int a) { return data[a + n]; }
  int MinSearch(function<bool(T)> F) {
    if (!F(data[1])) {
      return -1;
    }
    T L = M::id();
    int a = 1;
    while (a < n) {
      if (!F(M::op(L, data[a << 1]))) {
        L = M::op(L, data[a << 1]);
        a = (a << 1) + 1;
      } else {
        a <<= 1;
      }
    }
    return a - n;
  }
  int MinSearch(int v, function<bool(T)> F) {
    int a = v + n;
    T L = data[a];
    if (F(L)) {
      return v;
    }
    while (a > 1) {
      if ((a & 1) == 0) {
        if (F(M::op(L, data[a + 1]))) {
          a++;
          break;
        }
        L = M::op(L, data[a + 1]);
      }
      a >>= 1;
    }
    if (a == 1) {
      return -1;
    }
    while (a < n) {
      if (!F(M::op(L, data[a << 1]))) {
        L = M::op(L, data[a << 1]);
        a = (a << 1) + 1;
      } else {
        a <<= 1;
      }
    }
    return a - n;
  }
};
int A[200000];
SegmentTree<Monoid> Seg[9];
void Calc() {
  int N = rei();
  int Q = rei();
  for (int i = 0; i < N; i++) {
    A[i] = rei();
  }
  {
    vector<vector<pair<int, int>>> Origin(9, vector<pair<int, int>>(N));
    for (int i = 0; i < N; i++) {
      int x = A[i];
      for (int j = 0; j < 9; j++) {
        if (x % 10) {
          Origin[j][i] = {A[i], 1000000000};
        } else {
          Origin[j][i] = {1000000000, 1000000000};
        }
        x /= 10;
      }
    }
    for (int i = 0; i < 9; i++) {
      Seg[i].init(Origin[i]);
    }
  }
  for (int q = 0; q < Q; q++) {
    int type = rei();
    if (type == 2) {
      int l = rei() - 1;
      int r = rei();
      long long ans = 3000000000;
      for (int i = 0; i < 9; i++) {
        pair<int, int> pi = Seg[i].Query(l, r);
        if (pi.second != 1000000000) {
          long long c = pi.first;
          c += pi.second;
          ans = min(ans, c);
        }
      }
      if (ans == 3000000000) {
        cout << "-1\n";
      } else {
        cout << ans << "\n";
      }
    } else {
      int p = rei() - 1;
      int y = rei();
      int x = y;
      for (int j = 0; j < 9; j++) {
        if (x % 10) {
          Seg[j].Update(p, {y, 1000000000});
        } else {
          Seg[j].Update(p, {1000000000, 1000000000});
        }
        x /= 10;
      }
    }
  }
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  cout.tie(0);
  Calc();
  return 0;
}
