def main():
    r1 = input()
    n, m = map(int, r1.split(" "))
    v = ["~"] * n
    for v in range(m):
        r = input()
        s, c = map(int, r1.split(" "))
        v[s] = c
        if v[s] != "~" and v[s] != c:
            print(-1)
            return
    for x in range(len(v)):
        if v[x] == '~':
            v[x] = 0
    sv = "".join(v)
    res = int(sv)
    res_str = str(res)
    if len(sv) != len(res_str):
        print(-1)
        return
    print(res_str)

main()
    