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

    ans = [0 for i in range(N)]
    flag = [0 for i in range(N)]
    count = 0
    ans_t = []
    min_ans = 0
    for _ in range(M):

        s, c = map(int, input().split())
        if (s == 1) and (c == 0):
            pass
        elif ans[s-1] > c:
            ans[s-1] = c
            flag[s-1] = 1
        elif flag[s-1] == 0:
            ans[s - 1] = c

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

        '''
        if (c != 0) and (ans[s-1] > c) and (flag[s-1] == 1):
            ans[s-1] = c
        elif (flag[s-1] == 0):
            ans[s - 1] = c
            flag[s-1] = 1

    ans_tmp = 0
    for i in range(0, N):
        ans_tmp += (10 ** i) * ans[N-i-1]

    #print(ans_tmp)

    if len(str(ans_tmp)) < N:
        print(-1)
    else:
        print(ans_tmp)
    '''




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