#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> s(M), c(M), _s(M);
    REP(i,0,M){
        cin >> s[i] >> c[i];
        _s[i] = s[i];
    }

    sort(ALL(_s));
    ll D = _s[M-1];

    vector<ll> num(N, 0);
    bool f = true;
    if(D > N) f = false;
    else {
        REP(i,0,M) if(N != 1 && s[i] == 1 && c[i] == 0) f = false;
        else {
            REP(i,0,M) {
                if(num[s[i]] != 0 && num[s[i]] != c[i]) f = false;
                else {
                    num[[i]] = c[i];
                }
            }
            if(N != 1 && num[0] == 0) num[0] = 1;
        }
    }

    if(f) {
        REP(i,0,N) cout << num[i];
        cout << endl;
    }
    else _PR(-1);

    return 0;
}

/*



*/