#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M;
    cin >> N >> M;
    int num[N] = {};

    bool isPoss = 1;
    while(M--) {
        int a, b;
        cin >> a >> b;
        if (num[a-1] != 0 && num[a-1] != b || a == 1 && b == 0) isPoss = 0;
        else num[a-1] = b;
    }

    if (isPoss) {
        for(int i = 0; i < N; i++) {
            cout << num[i];
        }
    }
    else cout << "-1";
    return 0;
}
