#!/usr/bin/env python3
n, m = map(int, input().split())
l = [[] for _ in range(n)]
o = []
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    l[a] += [b]
if l[0] == []:
    l[0] += [1]
if l[0] == [0]:
    print(-1)
    exit()
for j in range(n):
    if len(set(l[j])) > 1:
        print(-1)
        exit()
    if l[j] == []:
        l[j] += [0]
for k in l:
    o.append(str(k[0]))
print(''.join(o))