#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
source:
    ll n, m;
    cin >> n >> m;

    ll s[m], c[m];
    rep(i, m) {
        cin >> s[i];
        cin >> c[i];
    }

    int ans[n];
    rep(i, n) { ans[i] = -1; }

    rep(i, m) {
        ll index = s[i] - 1;
        if (ans[index] == -1) {
            ans[index] = c[i];
        } else if (ans[index] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans_num = 0;
    ll first_index = -1;
    rep(i, n) {
        if (ans[i] != -1) {
            first_index = i;
            break;
        }
    }

    if (first_index == -1) {
        cout << 0 << endl;
        return 0;
    }
    if (ans[first_index] == 0 && first_index != n - 1) {
        cout << -1 << endl;
        return 0;
    }

    repd(i, first_index, n) {
        if (ans[i] != -1) {
            cout << ans[i];
        } else {
            cout << 0;
        }
    }
    cout << endl;

    return 0;
}

