def resolve_c():
    res = ''
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for i in range(m)]
    ans = [-1] * n
    flg = 0

    for p in l:
        if p[0] == 1 and p[1] == 0:
            print(-1)
            flg = 1
        elif ans[p[0]-1] != -1 and ans[p[0]-1] != p[1]:
            print(-1)
            flg = 1
        else:
            ans[p[0]-1] = p[1]

    for i in range(len(ans)):
        if i == 0 and ans[i] == -1:
            res = res + '1'
        elif ans[i] == -1:
            res = res + '0'
        else:
            res = res + str(ans[i])
    if flg == 0:
        print(int(res))
resolve_c()