using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Program { static void Main(string[] args) { new Magatro().Solve(); } } class Magatro { public void Solve() { Console.ReadLine(); string s = Console.ReadLine(); string t = Console.ReadLine(); Console.WriteLine(LenenshteinDistance(s, t)); } private int LenenshteinDistance(string a, string b) { int[,] dp = new int[a.Length + 1, b.Length + 1]; for (int i = 0; i <= a.Length; i++) { dp[i, 0] = i; } for (int i = 0; i <= b.Length; i++) { dp[0, i] = i; } for (int i = 1; i <= a.Length; i++) { for (int j = 1; j <= b.Length; j++) { int cost = a[i - 1] == b[j - 1] ? 0 : 1; dp[i, j] = (new int[] { dp[i - 1, j] + 1, dp[i, j - 1]+1, dp[i - 1, j - 1] + cost }).Min(); } } return dp[a.Length, b.Length]; } }