n, m = map(int, input().split())
lst = [x for x in range(n)]
dic = {}
not_found = False
for i in range(m):
    a, b = map(int, input().split())
    if str(a) not in list(dic.keys()):
        dic[str(a)] = b
    else:
        if dic[str(a)] != b:
            not_found = True
    lst[a-1] = b
if not_found:
    print(-1)
else:
    for i in range(n):
        if str(i+1) not in list(dic.keys()):
            lst[i] = 0
    lst = map(str, lst)
    res = ''.join(lst)
    if res[0] == '0':
        print(-1)
    else:
        print(int(res))