#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    string ans = "";
    for (int i = 0; i < N; i++) {
        ans += 'a';
    }
    bool f = true;
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        if (ans[s - 1] == 'a') {
            ans[s - 1] = char('0' + c);
        } else if (int(ans[s - 1]) - '0' != c) {
            f = false;
            break;
        }
        // cout << ans << endl;
    }

    if (N != 1) {
        if (ans[0] == '0') {
            f = false;
        }
        for (int i = 0; i < 3; i++) {
            if (ans[0] == 'a') {
                ans.erase(0, 1);
            } else
        }

    }

    for (char& a : ans) {
        if (a == 'a') {
            a = '0';
        }
    }

    // cout << ans.length() << endl;

    if (f && ans.length() > 0) {
        cout << ans << endl;
    } else {
        cout << "-1" << endl;
    }
    return 0;
}