import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Scanner; class Main { public static void main(String[] args) throws Exception { new Main().run(); } void run() { Scanner sc=new Scanner(System.in); int N=sc.nextInt(); int K=sc.nextInt(); long[] A=new long[N]; for(int i=0;i=1&&(r==K||A[r]==2))++r; while(l-1>=0&&A[l-1]>=1&&(l==K||A[l]==2))--l; long rc=0,lc=0; for(int i=K+1;i<=r;++i)rc+=A[i]; for(int i=K-1;i>=l;--i)lc+=A[i]; if(A[K]<=2){ System.out.println(A[K]+Math.max(rc,lc)); }else{ System.out.println(A[K]+rc+lc); } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }