N, M = map(int, input().split())
dic = {}
for _ in range(M):
    s, c = input().split()
    n = dic.get(s)
    if n is not None and n != c:
        print(-1)
        exit()
    dic[s] = c

lst = []
for i, k in enumerate(sorted(dic.keys()), 1):
    if k == str(i):
        lst.append(dic[k])
    else:
        lst.append("0")
        lst.append(dic[k])

ret = "".join(lst)
if len(ret) == N:
    print(ret)
else:
    print(-1)
