#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int s[m],c[m];
    rep(i,m) cin >> s[i] >> c[i];  //s[i]桁目がc[i]
    rep(i,1000){
        string str = to_string(i);
        int cnt = 0;
        rep(j,m){
            if(str[s[j]-1] -'0' == c[j]) cnt++;
        }
        if(cnt == m && str.size() == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}