N,M = map(int,input().split())
from collections import defaultdict
sc = defaultdict(set)
for _ in range(M):
    s,c = map(str,input().split())
    sc[int(s)].add(c)

sc_sorted = sorted(sc.items(), key=lambda x:x[0])

if N == 1:
    if len(sc[1]) > 1:
        print(-1)
    elif len(sc[1]) == 1:
        print(sc[1].pop())
    else:
        print(0)

ans = ""
for i in range(1,N+1):
    if len(sc[i]) > 1:
        print(-1)
        exit()

    if i == 1:
        if len(sc[i]) == 1:
            tmp = sc[i].pop()
            if tmp == "0":
                print(-1)
                exit()
            else:
                ans += tmp
        else:
            ans += "1"
    else:
        if len(sc[i]) == 1:
            ans += sc[i].pop()
        else:
            ans += "0"

print(ans)