#include<bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> result(N, -1);
    rep(i, M) {
        int s, c;
        cin >> s >> c;
        if(result[s-1]!=-1&&result[s-1]!=c){
            cout << "-1" << endl;
            return 0;
        }
        return[s-1] = c;
    }
    if (N==1) {
        cout << (result[0]==-1?0:result[0]) <<endl;
        return 0;
    }
    if (result[0]==-1) {
        result[0] = 1
    } else if (result[0] == 0) {
        cout << "-1" << endl;
        return 0;
    }
    rep(i, N) {
        cout << (result[i]==-1?0:result[i]);
    }
    cout << endl;
}