def main():
    n, m = map(int, input().split())
    ans = 0
    f = True
    for _ in range(m):
        s, c = map(int, input().split())
        if s == 1 and c == 0:
            f = False
        if (ans%(10**(n-s+1))) // (10**(n-s)) != 0 and (ans%(10**(n-s+1))) // (10**(n-s)) != c:
            f = False
        else:
            if (ans%(10**(n-s+1))) // (10**(n-s)) == 0:
                ans += c * (10**(n-s))
    if len(str(ans)) < n:
        ans += 10**(n-1)
    if f:
        print(ans)
    else:
        print("-1")


if __name__ == "__main__":
    main()