#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  string s , t  ;
  cin >> s >> t ;
  deque<char> S , T ;
  rep(i,n){
    S.push_back(s.at(i)) ;
    T.push_back(t.at(i));
  }
  if(s == t ) {
    cout << s.size() <<endl ; 
    return 0 ;
  }
  
  int ans = 2 * n ;
  
  rep(i,n){
    S.pop_front();
    T.pop_back();
    
    if( S == T){
      ans = S.size() + 2*(i+1) ;
      cout <<  ans <<endl ;
      return 0 ;
    }
  }
    
  
}

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll k, t; cin >> k >> t;
    vll a(t);
    Map m;
    ll mx = 0; ll s = 0;
    rep(i, 0, t){
        cin >> a[i];
        m[i] = a[i];
        s += a[i]; mx = max(mx, a[i]);
    }
    ll g = s - mx;
    if(mx < g){
        prtl(0);
    }else{
        prtl(mx - g - 1);
    }
}

