def main():

    N, M = (int(i) for i in input().split())

    from collections import defaultdict

    dic = defaultdict(set)

    for i in range(M):

        s, c = (int(i) for i in input().split())

        dic[s].add(c)

    if 0 in dic[1] and N != 1:

        return print(-1)

    for i in range(1, N+1):

        if len(dic[i]) > 1:

            return print(-1)

        elif not(dic[i]):

            dic[i].add(0 if i != 1 or N == 1 else 1)

    # print(dic)

    s = ""

    for i in range(1, N+1):

        s = s + str(dic[i].pop())

    print(s)





if __name__ == '__main__':

    main()

def main():

    N, M = (int(i) for i in input().split())

    dic = {}

    for i in range(M):

        s, c = (i for i in input().split())

        if s in dic.keys() and dic[s] != c:

            return print(-1)

        dic[s] = c

    for t in range(1000):

        t = str(t)

        if len(t) != N:

            continue

        for k, v in dic.items():

            if t[int(k)-1] != v:

                break

        else:

            return print(t)

    print(-1)





if __name__ == '__main__':

    main()

def main():
    N, M = (int(i) for i in input().split())
    from collections import defaultdict

    dic = defaultdict(set)
    for i in range(M):
        s, c = (int(i) for i in input().split())
        dic[s].add(c)
    if 0 in dic[1] and N != 1:
        return print(-1)
    for i in range(1, N + 1):
        if len(dic[i]) > 1:
            return print(-1)
        elif not (dic[i]):
            dic[i].add(0 if i != 1 or N == 1 else 1)
    # print(dic)
    s = ""
    for i in range(1, N + 1):
        s = s + str(dic[i].pop())
    print(s)


if __name__ == "__main__":
    main()

def main():
    N, M = (int(i) for i in input().split())
    dic = {}
    for i in range(M):
        s, c = (i for i in input().split())
        if s in dic.keys() and dic[s] != c:
            return print(-1)
        dic[s] = c
    for t in range(1000):
        t = str(t)
        if len(t) != N:
            continue
        for k, v in dic.items():
            if t[int(k) - 1] != v:
                break
        else:
            return print(t)
    print(-1)


if __name__ == "__main__":
    main()

-    from collections import defaultdict - -    dic = defaultdict(set) +    dic = {} -        s, c = (int(i) for i in input().split()) -        dic[s].add(c) -    if 0 in dic[1] and N != 1: -        return print(-1) -    for i in range(1, N + 1): -        if len(dic[i]) > 1: +        s, c = (i for i in input().split()) +        if s in dic.keys() and dic[s] != c: -        elif not (dic[i]): -            dic[i].add(0 if i != 1 or N == 1 else 1) -    # print(dic) -    s = "" -    for i in range(1, N + 1): -        s = s + str(dic[i].pop()) -    print(s) +        dic[s] = c +    for t in range(1000): +        t = str(t) +        if len(t) != N: +            continue +        for k, v in dic.items(): +            if t[int(k) - 1] != v: +                break +        else: +            return print(t) +    print(-1)