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

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

    int a[N] = {0};
    if (1 < N && M ==0) {
        a[0] = 1;
    }

    for (int m=0;m<M;m++) {
        int s, c;
        cin >> s >> c;
        int idx = s - 1;
        int idx_n = a[idx];
        if (c != 0) {
            if (idx_n ==0) {
                a[idx] = c;
                continue;
            }
            if (c < idx_n) {
                a[idx] = 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;
}
