#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
    vi a(N, -1);
    for (int i = 0; i < M; i++) {
        if (a[s[i] - 1] == -1) {
            a[s[i] - 1] = c[i];
        } else {
            if (a[s[i] - 1] != c[i]) {
                cout << -1 << endl;
                return;
            }
        }
    }

    int can_zero = false;
    for (int i = 0; i < N; i++) {
        if (a[i] == -1 || a[i] == 0) {
            if (a[i] == -1 && i == 0) {
                cout << 1;
                can_zero = true;
            } else if (a[i] == 0 && i == 0) {
                if (N == 1) {
                    cout << 0 << endl;
                    return;
                } else {
                    cout << -1 << endl;
                    return;
                }
            } else if (can_zero) {
                cout << 0;
            }
        } else if (a[i] >= 1 && a[i] <= 9) {
            can_zero = true;
            cout << a[i];
        }

    }
    if (!can_zero) {
        cout << 0;
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
    long long N;
    std::cin >> N;
    long long M;
    std::cin >> M;
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for (int i = 0; i < M; i++) {
        std::cin >> s[i];
        std::cin >> c[i];
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}
