#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N, -1);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        --s;
        if (A[s] != -1 && A[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        A[s] = c;
    }
    int base = 1;
    int end = 9;
    if (N == 2) {
        base = 10;
        end = 99;
    }
    if (N == 3) {
        base = 100;
        end = 999;
    }
    for (int i = base; i <= end; i++) {
        auto temp = to_string(i);
        bool check = true;
        for (int j = 0; j < N; j++) {
            if (A[j] == -1) continue;
            int num = temp[j] - '0';
            if (A[j] != num) {
                check = false;
            }
        }
        if (check) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}