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

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

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

    string str;
    int result[M];
    result[0] = -1;
    int flag = 0;

    if (N == 1) {
        for (int i=0; i<9; i++) {
            str = std::to_string(i);
            for (int j=0; j<M; j++) {
                if (atoi(str[s[j]]) == c[j]) {
                    result[j] = i;
                } else {
                    break;
                }
            }
        }
    } else if (N == 2) {
        for (int i=10; i<99; i++) {
            str = std::to_string(i);
            for (int j=0; j<M; j++) {
                if (atoi(str[s[j]]) == c[j]) {
                    result[j] = i;
                } else {
                    break;
                }
            }
        }
    } else {
        for (int i=100; i<999; i++) {
            str = std::to_string(i);
            for (int j=0; j<M; j++) {
                if (atoi(str[s[j]]) == c[j]) {
                    result[j] = i;
                } else {
                    break;
                }
            }
        }
    }    
    cout << result[0] << endl;
}