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

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

    int a[N] = {0};

    for (int m=0;m<M;m++) {
        int s, c;
        cin >> s >> c;
        if (c != 0 && c < a[s - 1] ) {
            a[s - 1] = c;
        }
        if (c != 0 && a[s - 1] == 0) {
            a[s - 1] = c;
        }
    }
    if (1 < N && a[0] == 0) {
        cout << "-1" << endl;
    } else {
        for (int i=0;i<N;i++) {
            cout << a[i];
        }
        cout << endl;
    }

    return 0;
}
