def main(n,m,sc):
    r = [-1]*n
    lst = get_unique_list(sc)
    for i in lst:
        x,y = i
        if r[x-1] == -1:
            r[x-1] = y
        elif r[x-1] != y:
            return "-1"
    if r[0] == 0:
        return "-1"
    elif r[0] == -1:
        res = "1" if n != 1 else "0"
    else:
        res = str(r[0])
    for i in range(1,len(r)):
        res = res + (str(r[i]) if r[i] != -1 else "0")
    return res

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
    
n,m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
print(main(n,m,sc))