def main():
    n, m = map(int, input().split())
    if m == 0:
        if len(str(n)) == 1:
            print(0)
            return
        else:
            print(-1)
            return
    s = []
    c = []
    for _ in range(m):
        x = list(map(int, input().split()))
        s.append(x[0])
        c.append(x[1])
    for i in range(1000):
        ans = [1 if len(str(i)) == n and str(i).zfill(3)[sx-1] == str(cx) else 0 for (sx, cx) in zip(s, c)]
        if all(ans):
            print(i)
            return
    print(-1)


if __name__ == "__main__":
    main()
