n, m = map(int, input().split())
res = [-1] * n
f = True
for i in range(m):
    s, c = map(int, input().split())
    s -= 1 # 0 ind
    if res[s] == -1 or res[s] == c:
        res[s] = c
    else:
        f = False
res = list(map(lambda x: x if x != -1 else 0, res))
#print(res)
if res[0] == 0:
    f = False
if f is True:
    res = "".join(list(map(str, res)))
    print(res)
else: # False
    print(-1)