N, M = map(int, input().split())
checker = [list(map(int, input().split())) for _ in range(M)]

#zero_flag = False
#c_list = [ _[1] for _ in checker]
#zero_check = [0 == i for i in c_list]

#ans = -1
#for i in range(M):
#    temp = 10 * (checker[i][0] - 1) + checker[i][1]

temp = [None] * N
for i in range(M):
    if temp[checker[i][0] - 1] == None:
        temp[checker[i][0] - 1] = checker[i][1]
    elif temp[checker[i][0] - 1] == checker[i][1]:
        continue
    else:
        print('-1')
        exit()

#None None  ~~^0 の場合
if temp[-1] == 0 and all(temp[:-2]) == None:
    print('0')
    exit()


#010とかの場合
zerocheck = False
for i in range(N):
    if temp[i] == None:
        continue
    elif temp[i] == 0:
        if zerocheck == False:
            zerocheck = True
            print('-1')
            exit()
    else:
        zerocheck = temp[i]




#None 1 None とか　1 None 0 とかの場合
for i in range(N):
    if temp[i]== None:
        temp[i] = 0


char_temp = "".join(map(str, temp))
print(char_temp)


