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

int main()
{
    int N, M;
    cin >> N >> M;
    char ans[N] = {};
    bool keta[N] = {false};

    for (int i = 0; i < N; ++i)
    {
        ans[i] = '0';
    }
    for (int i = 0; i < M; ++i)
    {
        int s;
        char c;
        cin >> s >> c;
        if (keta[s - 1])
        {
            if (ans[s - 1] != c)
            {
                cout << -1 << endl;
                return 0;
            }
        }
        ans[s - 1] = c;
        keta[s - 1] = true;
    }

    if (N != 1 && ans[0] == '0')
    {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < N; ++i)
    {
        cout << ans[i];
    }
    cout << endl;
}