def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    s = [sc[i][0] for i in range(M)]
    c = [sc[i][1] for i in range(M)]
    ans = [0]*N
    ans[0] = 1
    flag = [False]*N
    for i in range(M):
        if s[i]-1 == 0 and c[i] == 0 and N != 1:
            ans = "-1"
            break
        if flag[s[i]-1] and ans[s[i]-1] != c[i]:
            ans = "-1"
            break
        else:
            ans[s[i]-1] = c[i]
            flag[s[i]-1] = True
    if ans == "-1":
        print(ans)
    else:
        print(*ans,sep="")

if __name__ == '__main__':
    main()