#include <bits/stdc++.h>
using namespace std;

void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c)
{
    for (int i = 0; i < N; i++)
        s[i] = s[i] - 1;

    int num[N] = {0};
    for (int i = 0; i < N; i++)
    {
        if (num[s[i]] == 0)
        {
            num[s[i]] = c[i] + '0';
        }
        // 同じ桁に異なる数字を入れようとしたとき
        else if (num[s[i]] != c[i] + '0')
        {
            cout << "-1" << endl;
            return;
        }
    }

    for (int i = 0; i < N; i++)
    {
        if (num[i] == 0)
        {
            num[i] = '0';
        }
    }

    // 数字に戻す
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += (int)(num[i] - '0') * pow(10, N - i - 1);
    }
    if (N == 1 && ans == 0)
        cout << ans << endl;
    else if (pow(10, N - 1) <= ans && ans < pow(10, N))
        cout << ans << endl;
    else
        cout << ans << "-1" << 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;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> s(M);
    std::vector<long long> c(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &s[i]);
        scanf("%lld", &c[i]);
    }
    solve(N, M, std::move(s), std::move(c));
    return 0;
}
