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

int main()
{
    int N, M, x, y;
    bool z = false;
    cin >> N >> M;

    int list[N]{};

    for (int i = 0; i < M; i++)
    {
        cin >> x >> y;

        //先頭の桁が0
        if (x == 1 && y == 0)
        {
            if (N == 1)
                list[x - 1] = y;
            else
            {
                z = true;
                break;
            }
        }

        if (list[x - 1] == 0)
        {
            list[x - 1] = y;
        }
        else
        {
            if (list[x - 1] != y)
            {
                z = true;
                break;
            }            
        }
        
    }
    if(z)
        cout << -1;
    else
    {
        for (int i = 0; i < N; i++)
        {
            cout << list[i];
        }
    }
}