def main():
    N , M = map(int,input().split())
    val = [map(int,input().split()) for _ in range(M)]
    ans = [-1 for _ in range(N)]
    flag = True
    for i in range(M):
        p,q = val[i]
        if ans[p-1] != -1 and ans[p - 1] != q :
                flag = False
        ans[p-1] = q
    ans_val = 0
    for i in range(N):
        if ans[i] != -1 :
            ans_val += ans[i] * (10 ** (N - 1 -i))

    if (not flag):
        print(-1)
    else:
        print(ans_val)

if __name__ == '__main__':
    main()