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


if __name__ == '__main__':
    main()