#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  string s;
  string t;
  cin >> s;
  cin >> t;
  int start = 0;
  int _end = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != t[i]) {
      start = i;
      break;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] != t[i]) {
      _end = i;
      break;
    }
  }
  string S;
  map<char, int> M;
  string T;
  map<char, int> N;
  for (int i = start; i <= _end; i++) {
    S += s[i];
    M[s[i]]++;
    T += t[i];
    N[t[i]]++;
  }
  char temp;
  int counter = 0;
  for (map<char, int>::iterator f = M.begin(); f != M.end(); f++) {
    if (N[(*f).first] == 0) {
      temp = (*f).first;
      counter++;
    }
  }
  if (counter > 1) {
    printf("0");
    return 0;
  } else if (counter == 0) {
    string Drmp = S;
    S += T[T.size() - 1];
    int Number1 = 0;
    int Number2 = 0;
    int Ans = 0;
    for (int i = 1; i < S.size(); i++) {
      if (S[i] != T[i - 1]) {
        Number1++;
        break;
      }
    }
    S = Drmp;
    S = T[0] + S;
    for (int i = 0; i < S.size() - 1; i++) {
      if (S[i] != T[i]) {
        Number2++;
        break;
      }
    }
    if (Number1 == 0) {
      Ans++;
    }
    if (Number2 == 0) {
      Ans++;
    }
    if (Ans > 0) {
      cout << Ans;
      return 0;
    }
    S = Drmp;
    printf("0");
    return 0;
  } else {
    T += temp;
    int Number1 = 0;
    for (int i = 1; i < T.size(); i++) {
      if (T[i] != S[i - 1]) {
        Number1++;
      }
    }
    T = temp + T;
    int Number2 = 0;
    for (int i = 0; i < T.size() - 2; i++) {
      if (T[i] != S[i]) {
        Number2++;
      }
    }
    int Ans = 0;
    if (Number1 == 0) {
      Ans++;
    }
    if (Number2 == 0) {
      Ans++;
    }
    cout << Ans;
    return 0;
  }
  return 0;
}
