#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int s, n, cnt = 0;
cin >> s >> n;
deque<int> dq;
for (int i = 1; i <= s; i++)
dq.push_back(i);
for (int i = 0; i < n; i++)
{
int idx = 0, num;
cin >> num;
for (int i = 0; i < s; i++)
{
if (dq[i] == num)
{
idx = i;
break;
}
}
for (int i = 0; i < dq.size(); i++)
{
if (dq.front() == num)
{
dq.pop_front();
break;
}
if (idx < dq.size() / 2 + 1)
{
dq.push_back(dq.front());
dq.pop_front();
}
else
{
dq.push_front(dq.back());
dq.pop_back();
}
cnt++;
}
}
cout << cnt << '\n';
return 0;
}