n, m = map(int, input().split())
Lists = []
for i in range(m):
    Lists.append(list(map(int, input().split())))

for i in range(10 ** (n-1), 10 ** n):
    i_str = str(i)
    bool_list = []
    for j  in range(m):
        a = Lists[j][0]
        bool_list.append(str(Lists[j][1]) == i_str[a-1])
    
    if n == 1 and m == 0:
      print(0)
      break
    elif m == 0:
      print(-1)
      break
    elif bool_list == [True] * m:
        print(i)
        break
    elif i == 10**n - 1:
        print(-1)
    else:
        pass