# -*- coding: utf-8 -*-
import sys
import random

N,M = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(M)]
#%%
ans = -1
for i in range(1000):
    a = [0]*3
    tmp = i
    for j in range(3):
        a[2-j] = tmp%10
        tmp //= 10
    
    for s,c in sc:
        if a[s-1] != c:
            break
    else:
        if N==1:
            print(i)
        else:
            if a[3-N]!=0:
                print(i)
            else:
                continue
        
        sys.exit()
    continue
print(ans)
    