#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int N,M,s,c,ans = -1;
    cin >> N >> M;
    vector<int> a(3,-1);
    REP(i,M){
        cin >> s >> c;
        if(a[s-1] != -1){
            if(a[s-1] == c)// continue;
            else{
                cout << "-1" <<endl;
                return 0;
            }
        }if( N != 1 && (s == 1 && c == 0)){
            cout << "-1" <<endl;
            return 0;
        }else{
            a[s-1] = c;
        }
    }
    ans = 0;
    if(a[N-1] == -1) a[N-1] = 1;
    REP(i,N){
        if(a[i] == -1) a[i] = 0;
        ans += a[i];
        if(i != N-1)ans *= 10;
    }
   
    cout << ans <<endl;

    return 0;
}