import sys

N,M = map(int, input().split())
S = ["0"]*N

for _ in range(M):
    s,c = input().split()
    S[int(s)-1]=c

if N==1:
    print(int(S[0]))
    sys.exit()

if S[0]!="0":
    s = ""
    for i in range(N):
        s = s + S[i]
    print(int(s))
    sys.exit()

print(-1)