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

int main()
{
    int N, M, ans = 0;
    bool none = false;
    cin >> N >> M;
    vector<int> s(M), c(M);
    vector<bool> keta(N, false), keta2(N, false);

    //入力と、同じ桁で違うやつをはじく
    for (int i = 0; i < M; i++)
    {
        cin >> s.at(i) >> c.at(i);
        if (c.at(i) != 0)
        {
            keta.at(s.at(i) - 1) = true;
        }
        for (int j = 0; j < i; j++)
        {
            if (s.at(i) == s.at(j) && c.at(i) != c.at(j))
            {
                none = true;
            }
        }
    }
    //大きな位がゼロをはじく
    /*if (keta.at(0)==false)
    {
        none = true;
    }
    */

    //数を作る
    for (int i = 0; i < M; i++)
    {
        if (none == false && keta2.at(s.at(i) - 1) == false)
        {
            ans = ans + c.at(i) * pow(10, N - s.at(i));
            keta2.at(s.at(i) - 1) = true;
        }
    }

    if(ans<pow(10,N-1))
    {
        none = true;
    }
    if (none == false)
    {
        cout << ans << endl;
    }else
    {
        cout << -1 << endl;
    }
}
