import math
def main():
    N, M = map(int, input().split())

    ans = [0 for i in range(N)]
    count = 0
    for _ in range(M):
        s, c = map(int, input().split())

        tmp = ans
        tmp[s-1] = c
        ans_tmp, t_tmp = 0, 0
        for i in range(0, N):
            ans_tmp += (10 ** i) * ans[i]
            t_tmp += (10 ** i) * tmp[i]
        if t_tmp < ans_tmp:
            ans[s-1] = c
    a = 0
    for i in range(N):
        a += (10 ** i) * ans[N-i-1]
    #print(len(str(a)))
    if len(str(a)) < N:
        print(-1)
    else:
        print(a)



    return 0
if __name__ == '__main__':
    main()