#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

int main()
{
    int N, M;
    cin >> N >> M;

    int s[M];
    int c[M];
    rep(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--;
        s[i] = a;
        c[i] = b;
    }

    int S[N] = {};

    rep(i, 0, M) {
        if (S[s[i]] != 0 && S[s[i]] != c[i]) {
            cout << -1 << endl;
            return 0;
        }
        S[s[i]] = c[i];
    }

    if (N == 3 || N == 2) {
        if (S[0] == 0) {
            cout << -1 << endl;
            return 0;
        }
    }

    rep(i, 0, N) {
        cout << S[i];
    }
    cout << endl;

    return 0;
}