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

int main(void) {
    int N,M; cin >> N >> M;
    int X[N+5] = {0};
    int ans;
    for(int i=0; i<M; i++) {
        int s,c; cin >> s >> c;
        if(X[s] != 0) ans = -1;
            else X[s] = c;
    }
    
    if(ans == -1) ;
    else if(X[1] == 0) ans = -1;
        else {
            ans = X[1]*100 + X[2]*10 + X[3];
        }
    cout << ans << endl;
}