def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    tmp = [[] for _ in range(N)]
    for i in range(M):
        s,c = sc[i][0],sc[i][1]
        tmp[s-1].append(c)
    ans = []
    for i in range(N):
        if len(set(tmp[i])) >= 2:
            ans = "-1"
            break
    if ans == "-1":
        print(ans)
    else:
        cc = []
        for i in range(1000):
            st = list(str(i))
            for j in range(N):
                if len(tmp[j]) == 0 or len(st) < N:
                    continue
                if st[j] != str(tmp[j][0]):
                    ans = "-1"
                    break
                if j == N-1 and len(st) == N:
                    cc.append(i)
        print(cc)[0]


if __name__ == '__main__':
    main()