N, M = map(int, input().split(' '))
S = []
C = []


def main():
    ans = -1
    for i in range(M):
        s, c = map(int, input().split(' '))

        S.append(s)
        C.append(c)

    for num in reversed(range(10 ** N + 1)):

        # print('test', num)
        errflg = 0

        for j in range(M):
            # print(j)
            # print(S[j], C[j])

            try:
                if str(num)[S[j] - 1] == str(C[j]):
                    pass
                    # print('ok', S[j], C[j])
                else:
                    errflg = 1
            except:
                errflg = 1

        if errflg == 0:
            # print('ok', num)
            ans = num
        # else:
        #     print('ng', num)

    return ans


print(main())
