from collections import defaultdict
N, M = map(int, input().split())  # ちょうどN桁, M個のクエリ
correspondence = defaultdict(set)
for _ in range(M):
    s, c = map(int, input().split())
    correspondence[s].add(c)
# print(correspondence)
for k, v in correspondence.items():  # 要素が複数あったら-1を出力
    if len(v) > 1:
        print(-1)
        exit()

# correspondence = dict(sorted(correspondence.items(), key=lambda x: x[0]))
# print(correspondence)
ans = ""
for i in range(1, N+1):
    if i in correspondence.keys():
        ans += str(list(correspondence[i])[0])
    else:
        ans += "0"
if ans[0] == "0":
    ans = list(ans)
    ans[0] = "1"
    ans = "".join(ans)

if list(correspondence[1])[0] == 0:
    print(-1)
else:
    print(ans)
