#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i=0;i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
 

int main() {
    int n,m,ans=1000;
    cin >> n >> m;
    int s,c;
    bool f = true;
    vector<int> l(3,-1);

    rep(i,m){
        cin >> s >> c;
        s--;
        if(l[s]==-1||l[s]==c){
            l[s] = c;
        } else if(l[s]!=c){
            f = false;
        } else {
            l[s] = c;
        }
    }
    string S;
    bool flag=true;
    if(n!=1&&l[0]==0) f = false;
    rep(i,pow(10,n)){
        S = to_string(i);
        rep(j,S.size()){
            if((S[j]!=to_string(l[j]))&&l[j]!=-1){
                flag = false;
            }
        }
        if(flag){
            ans = min(ans,i);
        }
        flag = true;
    }
    if(f&&ans!=1000){
        cout << ans << endl;
    } else cout << -1 <<endl;
}