#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M);
    vector<char> c(M);
    for (int i = 0; i < M; i++) {
        cin >> s.at(i) >> c.at(i);
        s[i]--;
    }

    int st = 1;
    for (int i = 0; i < N - 1; i++) {
        st *= 10;
    }
    for (int i = st; i < st * 10; i++) {
        bool flag = true;
        string S = to_string(i);
        for (int j = 0; j < M; j++) {
            if (S[s[j]] != c[j]) flag = false;
        }
        if (flag) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}
