#include <bits/stdc++.h>
using namespace std;
int main()
{
int lineNumber , heightnumber;
cin >> lineNumber , heightnumber;
int sequence[lineNumber];
int inekSayisi = 7;
string das;
// count the frequency
for (int i = 0; i < lineNumber; ++i)
{
cin >> sequence[i];
}
int arraySize = sizeof(sequence)/sizeof(sequence[0]);
// for (int i = 0; i < arraySize; i++)
{
if(sequence[i] == 1)
{
for (int f = 1; f < arraySize-i; f++)
{
if (sequence[i+f] == 2)
{
inekSayisi++;
}else if (sequence[i+f] == 1)
{
break;
}
}
}
}
cout << inekSayisi << endl;
return 0;
}