#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    rep(i,n) {
        mp[i] = -1;
    }
    bool flag = true;
    rep(i,m) {
        int s, c;
        cin >> s >> c;
        if (mp[s-1] == -1) mp[s-1] = c;
        else {
            if (mp[s-1] == c) continue;
            else {
                flag = false;
                break;
            }
        }
    }
    if (mp[0] == 0) flag = false;
    rep(i,n) {
        if (i != 0 && mp[i] == -1) mp[i] = 0;
        if (i == 0 && mp[i] == -1) mp[i] = 1;
    }
    flag2 = false;
    rep(i,n) {
        if (mp[i] != 0) flag2 = true;
    }
    if (flag) flag = flag2;
    if (flag) {
        rep(i,n) {
            if (i != n-1) printf("%d", mp[i]);
            else printf("%d\n", mp[i]);
        }
    } else printf("-1\n");
    return 0;
}