def main():
    N,M = map(int,input().split())
    sc = [list(map(int,input().split())) for _ in range(M)]
    ans = "-1"
    for i in range(10**N):
        tmp = str(i)
        if len(tmp) < N:
            continue
        for j in range(M):
            if tmp[sc[j][0]-1] != str(sc[j][1]):
                break
        if j == M-1 and ans == "-1":
            ans = i
    print(ans)

if __name__ == '__main__':
    main()
