#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 105
typedef pair<int,int> P;
vector<vector<P>> block[7]={ { {P(0,0),P(1,0),P(2,0),P(3,0)},{P(0,0),P(0,1),P(0,2),P(0,3)} },
{ {P(0,0),P(0,1),P(1,0),P(1,1)} },
{ {P(0,1),P(0,2),P(1,0),P(1,1)}, {P(0,0),P(1,0),P(1,1),P(2,1)} },
{ {P(0,0),P(0,1),P(1,1),P(1,2)}, {P(0,1),P(1,0),P(1,1),P(2,0)} },
{ {P(0,1),P(1,0),P(1,1),P(1,2)}, {P(0,1),P(1,0),P(1,1),P(2,1)}, {P(0,0),P(0,1),P(0,2),P(1,1)}, {P(0,0),P(1,0),P(1,1),P(2,0)} },
{ {P(0,2),P(1,0),P(1,1),P(1,2)}, {P(0,0),P(1,0),P(2,0),P(2,1)}, {P(0,0),P(0,1),P(0,2),P(1,0)},{P(0,0),P(0,1),P(1,1),P(2,1)} },
{ {P(0,0),P(1,0),P(1,1),P(1,2)}, {P(0,0),P(0,1),P(1,0),P(2,0)}, {P(0,0),P(0,1),P(0,2),P(1,2)} , {P(0,1),P(1,1),P(2,0),P(2,1)} } } ;
int map[MAXN][MAXN];
int height[MAXN];
int C,num;
int ans;
bool is_range(int x, int y, vector<P> v){
for (int i = 0; i < 4; i++){
int nx = x + v[i].first;
int ny = y + v[i].second;
if (ny < 0 || nx >= MAXN || ny >= C || map[nx][ny]) return false;
}
return true;
}
int Check(int x, int y, vector<vector<P> > & v){
int sum = 0;
// 회전 종류
for (int i = 0; i < v.size(); i++){
if (!(is_range(x,y,v[i]))) continue;
for (int j = 0; j< v[i].size(); j++){
int nx = x + v[i][j].first;
int ny = y + v[i][j].second;
map[nx][ny] = 1;
}
bool flag = false;
for (int j = 0;j < v[i].size() && !flag; j++){
int nx = x + v[i][j].first+1;
int ny = y + v[i][j].second;
if (nx < MAXN && !map[nx][ny]) flag = true;
}
sum += !flag;
for (int j = 0; j< v[i].size(); j++){
int nx = x + v[i][j].first;
int ny = y + v[i][j].second;
map[nx][ny] = 0;
}
}
return sum;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> C >> num;
num--;
for (int i = 0 ;i < C; i++){
int tmp;
cin >> tmp;
height[i] = tmp;
while (tmp--){
map[MAXN-tmp-1][i] = 1;
}
}
for (int j = 0;j < C; j++){
for (int i = MAXN -1 -height[j]; i>=MAXN-6-height[j]; i--){
if (map[i][j]) continue;
ans += Check(i,j,block[num]);
}
}
cout << ans <<"\n";
return 0;
}