n, m = map(int,input().split())
SC = {}
num = ["0"]*n
for _ in range(m):
    s, c = map(int,input().split())
    num[s-1] = str(c)
    if s in SC and SC[s] != c:
        print(-1)
        exit()
    SC[s] = c

if all(i == "0" for i in num[:-1]):
    if len(num)-1 not in SC:
        print(-1)
        exit()

print(str(int("".join(num))))