#include<bits/stdc++.h>
using namespace std;

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n, m;
    cin >> n >> m;
    vector<i32> v(n), u(n);
    v[0] = 1;
    for (i32 i = 0; i < m; i++) {
        i32 s, c;
        cin >> s >> c, s--;
        if (u[s] && v[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        u[s] = 1;
        v[s] = c;
    }

    if (v[0] == 0 && find_if(begin(v)+1, end(v), [](auto a) { return a != 0; }) == end(v)) {
        cout << -1 << endl;
        return 0;
    }
    string ans;
    for (auto& e : v) ans.push_back(e + '0');
    cout << ans << endl;
}
