#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
class Node {
 public:
  pair<long long int, long long int> nums;
};
vector<vector<Node>> tree;
vector<vector<long long int>> values;
void build(int index, int l, int r, int i, vector<vector<Node>> &tree) {
  if (l > r) {
    return;
  }
  if (l == r) {
    tree[i][index].nums = {values[i][l], INF};
    return;
  }
  int mid = l + (r - l) / 2;
  build(index * 2, l, mid, i, tree);
  build(index * 2 + 1, mid + 1, r, i, tree);
  auto ans1 = tree[i][index * 2].nums;
  auto ans2 = tree[i][index * 2 + 1].nums;
  pair<long long int, long long int> ans = {INF, INF};
  if (ans1.first < ans2.first) {
    ans.first = ans1.first;
    if (ans1.second < ans2.first) {
      ans.second = ans1.second;
    } else {
      ans.second = ans2.first;
    }
  } else {
    ans.first = ans2.first;
    if (ans1.first < ans2.second) {
      ans.second = ans1.first;
    } else {
      ans.second = ans2.second;
    }
  }
  tree[i][index].nums = ans;
  return;
}
void update(int index, int x, int l, int r, int i, vector<vector<Node>> &tree) {
  if (x < l || x > r) {
    return;
  }
  if (x == l && x == r) {
    tree[i][index].nums = {values[i][x], INF};
    return;
  }
  int mid = l + (r - l) / 2;
  update(index * 2, x, l, mid, i, tree);
  update(index * 2 + 1, x, mid + 1, r, i, tree);
  auto ans1 = tree[i][index * 2].nums;
  auto ans2 = tree[i][index * 2 + 1].nums;
  pair<long long int, long long int> ans = {INF, INF};
  if (ans1.first < ans2.first) {
    ans.first = ans1.first;
    if (ans1.second < ans2.first) {
      ans.second = ans1.second;
    } else {
      ans.second = ans2.first;
    }
  } else {
    ans.first = ans2.first;
    if (ans1.first < ans2.second) {
      ans.second = ans1.first;
    } else {
      ans.second = ans2.second;
    }
  }
  tree[i][index].nums = ans;
  return;
}
pair<long long int, long long int> query(int index, int L, int R, int l, int r,
                                         int i, vector<vector<Node>> &tree) {
  if (L > r || R < l) {
    return {INF, INF};
  }
  if (L <= l && R >= r) {
    return tree[i][index].nums;
  }
  int mid = l + (r - l) / 2;
  auto ans1 = query(index * 2, L, R, l, mid, i, tree);
  auto ans2 = query(index * 2 + 1, L, R, mid + 1, r, i, tree);
  pair<long long int, long long int> ans = {INF, INF};
  int temp = 0;
  if (ans1.first < ans2.first) {
    ans.first = ans1.first;
    if (ans1.second < ans2.first) {
      ans.second = ans1.second;
    } else {
      ans.second = ans2.first;
    }
  } else {
    ans.first = ans2.first;
    if (ans1.first < ans2.second) {
      ans.second = ans1.first;
    } else {
      ans.second = ans2.second;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int x = (int)(ceil(log2(n)));
  int max_size = (1 << (x + 1)) - 1;
  b = a;
  tree = vector<vector<Node>>(9, vector<Node>(max_size + 1));
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j <= max_size; j++) {
      tree[i][j].nums = make_pair(INF, INF);
    }
  }
  values = vector<vector<long long int>>(9);
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] % 10) {
        values[i].push_back(b[j]);
      } else {
        values[i].push_back(INF);
      }
      a[j] /= 10;
    }
  }
  for (int i = 0; i < 9; i++) {
    build(1, 0, n - 1, i, tree);
  }
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      long long int ind, x;
      cin >> ind >> x;
      long long int y = x;
      for (int j = 0; j < 9; j++) {
        if (x % 10) {
          values[j][ind - 1] = y;
        } else {
          values[j][ind - 1] = INF;
        }
        x /= 10;
      }
      for (int j = 0; j < 9; j++) update(1, ind - 1, 0, n - 1, j, tree);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      long long int fans = 2e18 + 1;
      for (int i = 0; i < 9; i++) {
        auto ans = query(1, l, r, 0, n - 1, i, tree);
        long long int temp = ans.first + ans.second;
        fans = min(fans, temp);
      }
      if (fans >= 1e18) {
        cout << -1 << '\n';
      } else {
        cout << fans << '\n';
      }
    }
  }
  return 0;
}
