Calculate Edit Distance