#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>ans(N);
    vector<int>ok(N);
    vector<int>flag(N);
    for(int i = 0; i < M; i++) {
        int s,c;
        cin >> s >> c;
        if(s == 1 && c == 0) {
            cout << -1 << endl;
            return 0;
        }
        if(ok[s-1] == c || flag[s-1] == 0) {
            ans[s-1] = c;
            ok[s-1] = c;
            flag[s-1]++;
        }
        else {
            cout << -1 << endl;
            return 0;
        }
    }
    if(N == 1) {
        cout << ans[i];
    }
    else {
    for(int i = 0; i < N; i++) {
        if(i == 0) {
            if(ans[i] == 0 && flag[i] == 0) {
                cout << 1;
            }
            else {
                cout << ans[i];
            }
        }
        else {
            cout << ans[i];
        }
    }
    }
    cout << endl;
}