N, M = map(int,input().split())

d = dict([ (i,set()) for i in range(1, N+1)])

for i in range(M):
    s,c = map(int,input().split())
    d[s].add(c)

flag = 1


# if ((0 in d[1]) or (len(d[1]) > 1)) :
#     if 0 in d[1] and N == 1:
#         ans = "0"
#     else:
#         flag = 0
# else:
#     ans = str(list(d[1])[0]) if len(d[1]) else "1"
#     for i in range(2, N+1):
#         if len(d[i]) > 1:
#             flag = 0
#             break
#         elif len(d[i]) == 0:
#             ans += "0"
#         else:
#             ans += str(list(d[1])[0])

ans = ""

for i in range(1, N+1):

    if len(d[i]) > 1:
        flag = 0
        break
    elif len(d[i]) == 1:
        el = str(list(d[i])[0])
        if el =="0" and i == 1:
            if N == 1:
                ans ="0"
            else:
                flag = 0
                break
        else:
            ans += el
    elif len(d[i]) == 0:
        ans += "1" if i == 1 else "0"
    else:
        print("PROBLEMS!")

if flag:
    print(ans)
else:
    print(-1)
