N, M = map(int, input().split())
sc_dict = {}
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if sc_dict.get(s) is not None:
        if sc_dict.get(s) != c:
            print(-1)
            exit(0)
    else:
        sc_dict[s] = c

ans = 100000000
for i in range(10**N):
    tmp = list(str(i))
    flg = True
    for s, c in sc_dict.items():
        if len(tmp) >= s+1:
            if tmp[s] != str(c):
                flg = False
                break
            continue
        flg = False
        break

    if flg:
        ans = min(ans, i)

if ans != 100000000 and ans != 0:
    print(ans)
else:
    print(-1)
