#include<bits/stdc++.h>

using namespace std;



int main(){
    int ar[10];
    for(int i = 1; i < 10; i++) ar[i] = -1;
    int n, m;
    cin >> n >> m;
    int check = 0;
    while(m--){
        int in1, in2;
        cin >> in1 >> in2;
        if(ar[in1] >= 0 && ar[in1] != in2) check = 1;
        ar[in1] = in2;
    }
    int res[n+1] = {0};
    res[1] = 1;
    for(int i = 1; i <= 9; i++){
        if(ar[i] != -1) res[i] = ar[i];
    }
    if(res[1] == 0 && n > 1) check = 1;
    if(check == 1) cout << "-1\n";
    else{
        for(int i = 1; i <= n; i++){
            
            cout << res[i];
        }
        cout << endl;
    }
    
    return 0;
}