import sys

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

for _ in range(M):
    s,c = input().split()
    index = int(s)-1
    if Table[index]==-1:
        S[index]=c
        Table[index] = 0
    else:
        if int(S[index])>int(s):
            S[index]=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)