n, m = map(int, input().split())
sl = list(list(map(int, input().split())) for _ in range(m))
# print(sl)
sl = list(map(list, set(map(tuple, sl))))
# print(sl)

cnt = [0]*n
cnn = [-1]*n
for s in sl:
    if cnt[s[0]-1] == 0:
        cnt[s[0]-1] += 1
    else:
        print(-1)
        exit()

# if n != 0:
num = list(str('1'+'0'*(n-1)))
for s in sl:
    if s[1] == 0:
        print(-1)
        exit()
    # elif num[s[0]-1] != 1 and num[s[0]-1] != '0':
    #     print(-1)
    #     exit()
    elif num[s[0]-1] != str(s[1]):
        num[s[0]-1] = str(s[1])
        # if num > _num:
        #     num = _num
print(*num, sep='')
# else:
#     print(0)


