#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M;
    cin >> N >> M;
    int s[N], c[N];
    for (int i = 0; i < M; i++) {
        cin >> s[i] >> c[i];
    }
    int d[N]{};
    fill(d, d + N, -1);
    for (int i = 0; i < M; i++) {
        if (s[i] == 1 && c[i] == 0) {
            cout << "-1";
            return 0;
        }
        if (d[s[i] - 1] == -1) {
            d[s[i] - 1] = c[i];
        } else if (d[s[i] - 1] != c[i]) {
            cout << "-1\n";
            return 0;
        }
    }
    if (N == 1 && d[0] == -1) {
        cout << "0\n";
        return 0;
    }
    if (d[0] == -1) d[0] = 1;
    for (int i = 1; i < N; i++) {
        if (d[i] == -1) d[i] = 0;
    }
    for (int i : d) {
        cout << i;
    }
    cout << "\n";
    return 0;
}