#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    
    cin >> n >> m;
   
    int sm[m][2];
    for(int i = 0; i < m; ++i){
        int t1, t2;
        cin >> t1 >> t2;
        sm[i][0] = t1 - 1;
        sm[i][1] = t2;
    }
    
    int d[n] = {-1, -1, -1};
    int res = 0;
    
    //入力重複チェック
    for(int i = 0; i < m && res != -1; ++i){
        if(n > 1 && sm[i][0] == 0 && sm[i][1] == 0){
            // cout << sm[i][0] << "," << sm[i][1] << endl;
            res = -1;
            break;
        }
        
        for(int j = i + 1; j < m; ++j){
            if(sm[i][0] == sm[j][0] && sm[i][1] != sm[j][1]){
                res = -1;
                break;
            }
            
            d[sm[i][0]] = sm[i][1];
        }
    }
    
    if(res == -1){
        cout << res << endl;
        return 0;
    }
    
    for(int i = 0; i < n; ++i){
        if(d[i] != -1) res += pow(10, n - 1 - i) * d[i];
    }
    
    cout << res << endl;
    
    return 0;
}