//#pragma GCC optimize("O3,unroll-loops")
//#pragma loop_opt(on)
#include <bits/stdc++.h>
//#include <bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 998244353;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    int n, m;
    cin >> n >> m;
    bool can = true;
    vector<int> v(n, -1);
    Fr(i, 0, m) {
        int si, ci;
        cin >> si >> ci;
        si--;
        if (v[si] == -1 || v[si] == ci) v[si] = ci;
        else can = false;
    }
    int ans = -1;
    if (can && (n == 1 || v[0] != 0)) {
        ans = 0;
        Fr(i, 0, n) ans = ans*10 + max(v[i], int(!i));
    }
    cout << ans << endl;

}
