#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag1 = true;
  bool flag2 = true;
  int n;
  string s1, s2;
  vector<int> mistakes;
  cin >> n;
  cin >> s1;
  cin >> s2;
  for (int i = 0; i < n; i++)
    if (s1[i] != s2[i]) mistakes.push_back(i);
  if (mistakes.size() == 1) {
    cout << "2";
    return 0;
  } else if (mistakes.size() > 1) {
    int a = mistakes[0];
    int b = mistakes.back();
    for (int s1i = a + 1, s2i = a; s1i <= b; s1i++, s2i++)
      if (s1[s1i] != s2[s2i]) flag1 = false;
    swap(s1, s2);
    for (int s1i = a + 1, s2i = a; s1i <= b; s1i++, s2i++)
      if (s1[s1i] != s2[s2i]) flag2 = false;
    cout << flag2 + flag1;
    return 0;
  }
  cout << "0";
}
