#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
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;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    cin >> N >> M;
    vector<int> s(M);
    vector<char> c(M);
    REP(i, M) {
        cin >> s.at(i) >> c.at(i);
        s[i]--;
    }

    string str;
    REP(i, N) { str.push_back('.'); }

    REP(i, M) {
        if (str[s[i]] == '.') {
            str[s[i]] = c[i];
        } else {
            if (str[s[i]] != c[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    if (str[0] == '.') {
        str[0] = '1';
    }
    FOR(i, 1, N) {
        if (str[i] == '.') {
            str[i] = '0';
        }
    }

    int ans = stoi(str);
    cout << ans << endl;

    return 0;
}
