import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    long n, m;
    scan(n, m);
    auto S = new long[](m);
    auto C = new long[](m);
    // writeln(tmp);
    foreach (i; 0 .. m)
    {
        long s, c;
        scan(s, c);
        S[i] = s;
        C[i] = c;
    }
    foreach (i; 0 .. 10 ^^ 3)
    {
        string i_str = i.to!string();
        if (i_str.length == n)
        {
            // writeln(i);
            // writeln(isValid(i, S, C));

            if (isValid(i, S, C))
            {
                writeln(i);
                return;
            }
        }
    }
    writeln(-1);
}

bool isValid(long x, long[] S, long[] C)
{
    string x_str = x.to!string();
    foreach (i; 0 .. S.length)
    {
        if (x_str[S[i] - 1] != C[i] + '0')
        {
            // writeln(x_str[S[i] - 1], C[i]);
            return false;
        }
    }
    return true;

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}
