#include <bits/stdc++.h>
using namespace std;
struct STNode {
  int left, right, v1, v2;
  STNode *left_child, *right_child;
  STNode(int l, int r) {
    left = l, right = r, v1 = v2 = ((int)1e9 + 10);
    left_child = right_child = NULL;
  }
  pair<int, int> solve_min(pair<int, int> lv, pair<int, int> rv) {
    if (rv.first < lv.first) {
      swap(lv.first, lv.second);
      lv.first = rv.first;
    } else if (rv.first < lv.second)
      lv.second = rv.first;
    if (rv.second < lv.second) lv.second = rv.second;
    return lv;
  }
  pair<int, int> query(int l, int r) {
    if (right < l || left > r)
      return (make_pair(((int)1e9 + 10), ((int)1e9 + 10)));
    if (left >= l && right <= r) return {v1, v2};
    pair<int, int> lv = left_child == NULL
                            ? (make_pair(((int)1e9 + 10), ((int)1e9 + 10)))
                            : left_child->query(l, r);
    pair<int, int> rv = right_child == NULL
                            ? (make_pair(((int)1e9 + 10), ((int)1e9 + 10)))
                            : right_child->query(l, r);
    return solve_min(lv, rv);
  }
  void update(int p, int v) {
    if (left == right) {
      v1 = v;
      return;
    }
    int mid = (left + right) >> 1;
    if (p <= mid) {
      if (left_child == NULL) left_child = new STNode(left, mid);
      left_child->update(p, v);
    } else {
      if (right_child == NULL) right_child = new STNode(mid + 1, right);
      right_child->update(p, v);
    }
    pair<int, int> lv = left_child == NULL
                            ? (make_pair(((int)1e9 + 10), ((int)1e9 + 10)))
                            : make_pair(left_child->v1, left_child->v2);
    pair<int, int> rv = right_child == NULL
                            ? (make_pair(((int)1e9 + 10), ((int)1e9 + 10)))
                            : make_pair(right_child->v1, right_child->v2);
    pair<int, int> sol = solve_min(lv, rv);
    v1 = sol.first, v2 = sol.second;
  }
};
STNode* items[9];
void add_item(int index, int num) {
  int original = num;
  for (int pos = 0; num > 0; ++pos) {
    int d = num % 10;
    if (d) items[pos]->update(index, original);
    num /= 10;
  }
}
void erase_item(int index, int num) {
  for (int pos = 0; num > 0; ++pos) {
    int d = num % 10;
    if (d) items[pos]->update(index, ((int)1e9 + 10));
    num /= 10;
  }
}
int get_subset(int l, int r) {
  int ans = ((int)1e9 + 10) + ((int)1e9 + 10);
  for (int pos = 0; pos < 9; ++pos) {
    int a = ((int)1e9 + 10), b = ((int)1e9 + 10);
    pair<int, int> curr = items[pos]->query(l, r);
    a = curr.first, b = curr.second;
    if (a != ((int)1e9 + 10) && b != ((int)1e9 + 10) && a + b < ans)
      ans = a + b;
  }
  return ans == ((int)1e9 + 10) + ((int)1e9 + 10) ? -1 : ans;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 0; i < 9; ++i) {
    items[i] = new STNode(1, n);
  }
  vector<int> arr(n + 1);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i]);
    add_item(i, arr[i]);
  }
  for (int t, a, b; q--;) {
    scanf("%d%d%d", &t, &a, &b);
    if (t == 1) {
      erase_item(a, arr[a]);
      arr[a] = b;
      add_item(a, arr[a]);
    } else {
      printf("%d\n", get_subset(a, b));
    }
  }
}
