#include <iostream>
#include <cstring>
using namespace std;

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