#!/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

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

for ii,i in enumerate(bit):
    if i == 1:
        ans += sc[ii+1]*(10**(2-ii))

if ans == 0:
    print(-1)
else:
    print(ans)