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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> v(N, -1);
    bool ok = true;
    REP(i,M){
        int s, c;
        cin >> s >> c;
        --s;
        if(v[s] == -1){
            v[s] = c;
        }
        else if(v[s] != c){
            ok = false;
        }
    }

    if(!ok) cout << -1 << endl;
    else{
        if(N == 1){
            if(M == 0) cout << 0 << endl;
            else cout << v[0] << endl;
        }
        else{
            if(v[0] == 0) cout << -1 << endl;
            else{
                REP(i,N){
                    if(v[i] != -1) cout << v[i];
                    else{
                        if(i == 0) cout << 1;
                        else cout << 0;
                    }
                }
                cout << endl;
            }
        }
    }
}