#include<bits/stdc++.h>
using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;

    int s[10] = {0};
    int c[10] = {0};
    for (int i=1; i<=M; i++) {
        cin >> s[i] >> c[i];
    }

    for (int i=1; i<=M; i++) {
        if ((s[i] == 1) && (c[i] == 0) && (N == 3)) {
            cout << -1 << endl;
            return 0;
        }
        if ((s[i] == 2) && (c[i] == 0) && (N == 2)) {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i=1; i<=M; i++) {
        if ((N != 3) && (s[i] == 1)) {
            cout << -1 << endl;
            return 0;
        }
        if ((N != 3) && (N != 2) && (s[i] == 2)) {
            cout << -1 << endl;
            return 0;
        }
    }

    bool R[5] = {false};
    int  D[5] = {0};

    for (int i=1; i<=M; i++) {
        int r = s[i];
        int d = c[i];
        if (R[r] != true) {
            R[r] = true;
            D[r] = d;
            continue;
        }
        if (D[r] != d) {
            cout << -1 << endl;
            return 0;
        }
    }

    if ((N == 3) && (num[1] == 0)) num[1] = 1;
    if ((N == 2) && (num[2] == 0)) num[2] = 1;
    cout << D[1] * 100 + D[2]  * 10 + D[3] << endl;

//    if (N == 3) cout << D[1] * 100 + D[2]  * 10 + D[3] << endl;
//    if (N == 2) cout <<              D[1]  * 10 + D[2] << endl;
//    if (N == 1) cout <<                           D[1] << endl;

    return 0;

}