using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split(' ');
            var N = a[0].ToInt();
            var M = a[1].ToInt();
            var l = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < M ; i++)
            {
                var a2 = Console.ReadLine().Split(' ');
                var s = a2[0].ToInt();
                var c = a2[1].ToInt();
                if (l.Any(x => x.Key == s && x.Value != c))
                {
                    Console.WriteLine(-1);
                    return;
                }
                if (N < s)
                {
                    Console.WriteLine(-1);
                    return;
                }
                if(N == 3 && s == 1 && c == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                if(N == 2 && s == 2 && c == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                l.Add(new KeyValuePair<int, int>(s, c));
            }
            var ans = 0;
            if (l.Any(x => x.Key == 1))
            {
                ans += l.FirstOrDefault(x => x.Key == 1).Value * 100;
            }
            else
            {
                if(N == 3) ans += 100;
            }
            if (l.Any(x => x.Key == 2))
            {
                ans += l.FirstOrDefault(x => x.Key == 2).Value * 10;
            }
            else
            {
                if (N == 2) ans += 10;
            }
            if (l.Any(x => x.Key == 3))
            {
                ans += l.FirstOrDefault(x => x.Key == 3).Value * 1;
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }

    public static class Extentions
    {
        public static int ToInt(this object obj)
        {
            return int.Parse(obj.ToString());
        }

        public static decimal ToDecimal(this object obj)
        {
            return decimal.Parse(obj.ToString());
        }
    }
}
