#!/usr/bin/env python3
import sys
input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

n,m = inn()
sc = {}
for i in range(m):
    nn,mm = inn()
    if nn in sc.keys():
        if sc[nn] != mm:
            print(-1)
            exit()
    sc[nn] = mm

bit = [0,0,0]
for i in [1,2,3]:
    if i in sc.keys():
        bit[i-1] = 1

ans = 0
if bit[2] == 1:
    ans += sc[3]

if bit[1] == 1:
    if sc[2] == 0:
        if bit[0] == 1:
            if sc[1] == 0:
                print(-1)
                exit()
            else:
                ans += sc[2]*10
else:
    if bit[0] == 0:
        print(ans)
        exit()
    else:
        if sc[1] == 0:
            print(-1)
            exit()
        else:
            ans += sc[1]*100
            print(ans)
