using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var nm = Console.ReadLine().Split(' ');
        var n = int.Parse(nm[0]);
        var m = int.Parse(nm[1]);

        var sc = new KeyValuePair<int, int>[m];
        for (int i = 0; i < sc.Length; ++i)
        {
            var sc_ = Console.ReadLine().Split(' ');
            sc[i] = new KeyValuePair<int, int>(int.Parse(sc_[0]), int.Parse(sc_[1]));
        }

        var result = new int[n];
        for (int i = 0; i < result.Length; ++i)
            result[i] = -1;

        foreach (var sc_ in sc)
        {
            var r = result[sc_.Key - 1];
            if (r != -1 && r != sc_.Value)
            {
                Console.WriteLine(-1);
                return;
            }
            result[sc_.Key - 1] = sc_.Value;
        }
        if (result[0] <= 0)
        {
            Console.WriteLine(n == 1 ? 0 : -1);
            return;
        }

        int answer = 0;
        int rank = 1;
        for (int i = 1; i < n; ++i)
            rank *= 10;
        for (int i = 0; i < result.Length; ++i, rank /= 10)
        {
            var r = result[i];
            if (r > 0)
                answer += r * rank;
        }

        Console.WriteLine(answer);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}
