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

lst = [0] * N
for k, v in dic.items():
    lst[k - 1] = v

if len(lst) != 0 and lst[0] == 0:
    lst[0] = 1

print("".join(map(str, lst)))
