#include <bits/stdc++.h>
#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];

    int wrong = -1
    int keta[3];
    rep(i,3) keta[i] = -1;
    rep(i,m) {
        rep(j,n) {
            if ((c[i] != keta[s[i]-1]) && (keta[s[i]-1] > -1)) {
                cout << wrong << endl;
                return 0;
            }
        }
        keta[s[i]-1] = c[i];
    }

    // cout << keta[0] << keta[1] << keta[2] << endl;
    
    if (keta[n-1] < 0) {
        cout << wrong << endl;
        return 0;
    }
    
    
    rep(i,n) {
        if (keta[i]<0) {
            keta[i] = 0;
        }
    }
    
    int res = keta[0]*100 + 10*keta[1] + keta[2];
    
    cout << res << endl;
    
    
    
    
    
    return 0;
    
}

