def main():
    n, m = map(int, input().split())
    num = [set() for _ in range(n)]
    ans = ""
    for _ in range(m):
        s, v = input().split()
        num[int(s)-1].add(v)
    if n > 1 and num[0] and list(num[0])[0] == "0":
        print(-1)
        return
    for i in num[:-1]:
        if len(i) == 0:
            ans += "0"
        elif len(i) == 1:
            ans += list(i)[0]
        else:
            print(-1)
            return
    if len(num[-1]) > 1:
        print(-1)
        return
    if len(num[-1]) == 1:
        ans += list(num[-1])[0]
    else:
        if m == 1:
            ans += "0"
        else:
            ans += "1"
    print(ans)

if __name__ == "__main__":
    main()