n, m = map(int,input().split())
n_list = []

for i in range(m):
    s, c = map(int,input().split())
    n_list.append([s, c])

ans = -1
i = 0
string = ""
string_list = []

while i < 1000:
    flag = 0
    i_string = str(i)
    string_list = list(i_string)
    if len(string_list) != n:
        i += 1
        continue
    for j in range(m):
        s, c = n_list[j][0], n_list[j][1]
        if int(string_list[s-1]) == c:
            flag = 1
        else:
            flag = 0
            break
    if flag == 1:
        print(i)
        ans = i
        break
    i += 1


if ans == -1:
    print(-1)
