n, m = map(int, input().split())
dic = {i: [] for i in range(1, n + 1)}
for _ in range(m):
    s_, c_ = map(int, input().split())
    if dic[s_]:
        if dic[s_][0] != c_:
            print(-1)
            exit()
        else: continue
    dic[s_].append(c_)
res = ""
if dic[1] and dic[1][0] == 0:
    print(-1)
    exit()
for k in dic.keys():
    if dic[k]:
        res += str(dic[k][0])
    else:
        if k == 1:
            res += "1"
        else:
            res += "0"
print(res)