from collections import defaultdict

def main():
    N, M = map(int, input().split())
    d = defaultdict(int)
    for _ in range(M):
        s, c = map(int, input().split())
        if d[s]:
            if d[s] != c:
                print(-1)
                exit()
        d[s] = c

    ans = [0] * N
    for i, j in d.items():
        ans[i-1] = j

    str_ans = ''
    for a in ans:
        str_ans += str(a)

    if str_ans.count('0') == N and N != 1:
        print(-1)
        exit()
    print(str_ans)



if __name__ == "__main__":
    main()