#n = int(input())
#s = input()
#n, k= map(int,input().split())
#da = list(map(int,input().split()))

n,m = map(int,input().split())
da = [list(map(int,input().split())) for i in range(m)]

ans = -1
for i in range(10**(n)):
    now = str(i)
    ju = True
    for j in range(m):
        if len(now) < da[j][0]:
            ju = False
            break
        if now[da[j][0]-1] != str(da[j][1]):
            ju= False
    if ju and len(str(ans)) == n:
        ans = i
        break

print(ans)