func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long int mod = 1e9 + 7;   long int i, j, n, t, m, k;   vector<pair<long int, long int> > a, b;   set<long int> c;   bool cmp(const pair<long int, long int> &l, const pair<long int, long int> &r) {     return l.first < r.first;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (long int i = 0; i < m; i++) {       cin >> j;       a.push_back(make_pair(j, i));       c.insert(j);     }     sort(a.begin(), a.end());     for (long int i = 0; i < a.size(); i++) {       if ((i + 1) < a.size()) {         long int rag = a[i].second, bha = a[i].second;         j = i + 1;         while (a[i].first == a[j].first) {           rag = max(rag, a[j].second);           bha = min(bha, a[j].second);           j++;           if (j >= a.size()) break;         }         i = j - 1;         b.push_back(make_pair(a[i].first, bha));         b.push_back(make_pair(a[i].first, rag));       } else {         b.push_back(make_pair(a[i].first, a[i].second));         b.push_back(make_pair(a[i].first, a[i].second));       }     }     for (long int i = 1; i < n + 1; i++) {       long int l, rag = -1, bha = -1, rag1 = -1, bha1 = -1;       l = lower_bound(b.begin(), b.end(), pair<long int, long int>(i, 0), cmp) -           b.begin();       if (l >= b.size()) l--;       if (b[l].first == i) {         bha = b[l].second;         rag = b[l + 1].second;       }       l = lower_bound(b.begin(), b.end(), pair<long int, long int>(i + 1, 0),                       cmp) -           b.begin();       if (l >= b.size()) l--;       if (b[l].first == i + 1) {         bha1 = b[l].second;         rag1 = b[l + 1].second;       }       if ((rag == -1 && bha == -1) && (rag1 == -1 && bha1 == -1))         continue;       else if ((rag != -1 && bha != -1) && (rag1 != -1 && bha1 != -1)) {         if (bha < rag1) t++;         if (bha1 < rag) t++;       }     }     t += c.size();     t = ((3 * n) - 2) - t;     cout << t;     return 0;   }   