def main():
    n,m = map(int, input().split())
    ans = [0] * n
    flg = 0
    for i in range(m):
        j,k = map(int, input().split())
        if ans[j-1] == 0:
            ans[j-1] = k
        elif ans[j-1] != 0 and ans[j-1] != k:
            flg = -1
    if flg == -1:
        print(flg)
    elif ans[0] == 0:
        print(-1)
    else:
        print(ans[0],ans[1],ans[2],sep="")

if __name__ == '__main__':
    main()