#include <bits/stdc++.h>
using namespace std;
int n;
string s1, s2;
int l1, r2;
int main() {
  cin >> n >> s1 >> s2;
  for (int i = 0; i < n; i++) {
    if (s1[i] != s2[i]) {
      l1 = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s1[i] != s2[i]) {
      r2 = i;
      break;
    }
  }
  if (l1 >= r2) {
    cout << 2 << endl;
    return 0;
  }
  int cnt = 2;
  for (int i = l1 + 1; i <= r2; i++) {
    if (s1[i] != s2[i - 1]) {
      cnt--;
      break;
    }
  }
  for (int i = l1 + 1; i <= r2; i++) {
    if (s2[i] != s1[i - 1]) {
      cnt--;
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}
