def main():
    n,m = map(int,input().split())
    li = [-1 for i in range(n)]
    for i in range(m):
        s,c = map(int,input().split())
        if li[s-1] == -1: 
            li[s-1] = c
        elif li[s-1] == c:
            continue
        else:
            print(-1)
            exit()
    if li[0]  == 0 and n != 1:
        print(-1)
        exit()
    else:
        for i in range(n):
            if li[i] == -1:
                li[i] = 0
    ans = 0
    for i in range(n):
        ans += li[i] * 10 ** (n-i-1)
    print(ans)
      

if __name__ == '__main__':
  main()