#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   const int INF = 1e9 + 5;   int read(int base = 10) {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = x * base + ch -  0 , ch = getchar();     return x;   }   struct Node {     int num[12][2];   } tree[N << 2];   void push_up(int o, int l, int r) {     int tmp[4];     for (int ii = 1; ii <= 11; ii++) {       tmp[0] = tree[o << 1].num[ii][0];       tmp[1] = tree[o << 1].num[ii][1];       tmp[2] = tree[o << 1 | 1].num[ii][0];       tmp[3] = tree[o << 1 | 1].num[ii][1];       sort(tmp, tmp + 4);       tree[o].num[ii][0] = tmp[0];       tree[o].num[ii][1] = tmp[1];     }   }   void build(int o, int l, int r) {     if (l == r) {       int x = read();       int tmp = x;       for (int ii = 1; ii <= 11; tmp /= 10, ii++) {         if (tmp % 10 == 0) {           tree[o].num[ii][0] = tree[o].num[ii][1] = INF;           continue;         }         tree[o].num[ii][0] = x;         tree[o].num[ii][1] = INF;       }       return;     }     int mid = (l + r) >> 1;     build(o << 1, l, mid);     build(o << 1 | 1, mid + 1, r);     push_up(o, l, r);   }   int id, x;   void update(int o, int l, int r) {     if (l == r) {       int tmp = x;       for (int ii = 1; ii <= 11; ii++, tmp /= 10) {         if (tmp % 10) {           tree[o].num[ii][0] = x;           tree[o].num[ii][1] = INF;         } else {           tree[o].num[ii][0] = tree[o].num[ii][1] = INF;         }       }       return;     }     int mid = (l + r) >> 1;     if (id <= mid)       update(o << 1, l, mid);     else       update(o << 1 | 1, mid + 1, r);     push_up(o, l, r);   }   int L, R, ans[12][2];   int tmp[4];   void query_up(int o, int i) {     tmp[0] = ans[i][0];     tmp[1] = ans[i][1];     tmp[2] = tree[o].num[i][0];     tmp[3] = tree[o].num[i][1];     sort(tmp, tmp + 4);     ans[i][0] = tmp[0];     ans[i][1] = tmp[1];   }   void query(int o, int l, int r) {     if (L <= l && r <= R) {       for (int ii = 1; ii <= 11; ii++) {         query_up(o, ii);       }       return;     }     int mid = (l + r) >> 1;     if (L <= mid) query(o << 1, l, mid);     if (R > mid) query(o << 1 | 1, mid + 1, r);   }   int main() {     int n = read(), m = read();     build(1, 1, n);     while (m--) {       int op = read();       if (op == 1) {         id = read(), x = read();         update(1, 1, n);       } else {         L = read(), R = read();         for (int i = 1; i <= 11; i++) ans[i][0] = ans[i][1] = INF;         query(1, 1, n);         int all = INF * 2;         ;         for (int i = 1; i <= 11; i++) {           if (ans[i][0] == INF || ans[i][1] == INF) continue;           all = min(all, ans[i][0] + ans[i][1]);         }         if (all == INF * 2) {           cout <<  -1 n ;         } else {           cout << all <<   n ;         }       }     }   }   