#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

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

    string tmp = to_string(0);
    bool flag = false;
    for(P p : vec) {
        if(tmp[p.first-1] - '0' != p.second) {
            flag = true;
        }
    }
    if (!flag) {
        PRINT(i);
        return 0;
    }

    FOR(i, pow(10, N-1), pow(10, N)) {
        string tmp = to_string(i);
        bool flag = false;
        for(P p : vec) {
            if(tmp[p.first-1] - '0' != p.second) {
                flag = true;
            }
        }
        if (!flag) {
            PRINT(i);
            return 0;
        }
    }
    PRINT(-1);
    return 0;
} 