def main():

    N, M = map(int, input().split())

    if M == 0:
        if N == 1: return 0
        else: return pow(10, N-1)
    
    if N == 1:
        s, c = map(int, input().split())
        if s == 1: return c
        else: return -1

    sc = []
    for _ in range(M):
        s, c = map(int, input().split())
        sc.append([s, c])

    for v in range(pow(10, N-1), pow(10, N)):
        t = str(v)
        if all(t[s-1] == str(c) for s, c in sc):
            return v
    return -1

if __name__ == '__main__':
    print(main())