
def main():
    n,m = map(int,input().split())
    answer = -1
    num = [-1] * n
    mujun = False
    for _ in range(m):
        s,c = map(int,input().split())
        s = s-1
        if num[s] == -1 or num[s] == c:
            num[s] = c
        else:
            mujun = True
            break
    if mujun or num[0] == 0:
        print(-1)
    else:
        if num[0] == -1:
            num[0] = 1
        num = [0 if i==-1 else i for i in num]
        print(int("".join(map(str,num))))



if __name__ == '__main__':
    main()
