#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); ++i)
using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    int s[m], c[m];
    rep(i, m) cin >> s[i] >> c[i];

    int answer = -1;
    int first = 0;
    int end = 10;
    if (n == 2)
    {
        first = 10;
        end = 100;
    }
    if (n == 3)
    {
        first = 100;
        end = 1000;
    }

    for (int i = first; i < end; i++)
    {
        bool ok[m] = {false};
        int hikaku[n];
        int buf = i;
        rep(i, n)
        {
            hikaku[n - i - 1] = buf % 10;
            buf /= 10;
        }

        rep(j, m)
        {

            if (hikaku[s[j] - 1] == c[j])
            {
                ok[j] = true;
                     }
        }

        bool ans = true;
        rep(j, m) if (!ok[j]) ans = false;
        if (ans)
        {
            answer = i;
            break;
        }
    }
    cout << answer << endl;
    return 0;
}