#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
int main() {
//用数组存储包裹编号,再创建一个按编号从小到大排序好的数组
//在原数组和排序数组中分别维护一个窗口,不断枚举右端点,记录窗口中的最大值和最小值
//当且仅当两个窗口中的最大值和最小值都相等时,这个窗口是可以被划分成一个批次的
//成功划分一个批次后,将窗口左端点移到右端点右一位,继续枚举窗口右端点直到末尾
int num = 0;
int res = 0;
vector<int> bags;
while (cin >> num) {
bags.push_back(num);
}
int len = bags.size();
vector<int> sorted_bags(bags);
sort(sorted_bags.begin(), sorted_bags.end());
//同时在原数组和排序数组中维护大小相同的窗口
//两个窗口的最值
int max1 = bags[0], min1 = bags[0];
int max2 = sorted_bags[0], min2 = sorted_bags[0];
for (int right = 0; right < len; right++) {
//更新两个窗口各自的最大值和最小值
max1 = max(max1, bags[right]);
min1 = min(min1, bags[right]);
max2 = max(max2, sorted_bags[right]);
min2 = min(min2, sorted_bags[right]);
//判断窗口是否可以划分成一个批次
if (max1 == max2 && min1 == min2) {
res += 1; //批次增加
//重置窗口最值
if (right != len - 1) {
min1 = max1 = bags[right + 1];
min2 = max2 = sorted_bags[right + 1];
}
}
}
cout << res;
return 0;
}
// 64 位输出请用 printf("%lld")