/*
TASK:seq
LANG:C++
*/

#include <ctime>
clock_t start = std::clock();

#include <map>
#include <cstdio>
#include <climits>

typedef signed int ind;
typedef unsigned int numval;

void read_ind(ind& n) {std::scanf("%d", &n);}
void write_ind(const ind& n) {std::printf("%d", n);}
void read_numval(numval& n) {std::scanf("%u", &n);}
void write_numval(const numval& n) {std::printf("%u", n);}
void write(const char *s) {std::printf("%s", s);}

ind infinity = INT_MAX;

class locator
{
public:
	locator() : min(infinity), max(-infinity) {}

	void put(const ind& n) {if (min > n) min = n; if (max < n) max = n;}

	ind min;
	ind max;
};

int main()
{
	std::map<numval, locator> m;
	ind n; read_ind(n); numval x;
	for (ind i = 0; i < n; i++)
	{
		read_numval(x);
		m[x].put(i);
	}

	bool right = true;
	ind flips = 0;
	ind cp = 0;
	for (std::map<numval, locator>::iterator it = m.begin(); it != m.end(); it++)
	{
		const locator& l = it->second;

		if (right)
			if (cp <= l.min)
				cp = l.max;
			else
			{
				cp = l.min;
				flips++;
				right = !right;
			}
		else if (cp >= l.max)
				cp = l.min;
			else
			{
				cp = l.max;
				flips++;
				right = !right;
			}
	}

	cp = n-1;
	ind nflips = flips;
	flips = 0;
	right = false;
	for (std::map<numval, locator>::iterator it = m.begin(); it != m.end(); it++)
	{
		const locator& l = it->second;

		if (right)
			if (cp <= l.min)
				cp = l.max;
			else
			{
				cp = l.min;
				flips++;
				right = !right;
			}
		else if (cp >= l.max)
				cp = l.min;
			else
			{
				cp = l.max;
				flips++;
				right = !right;
			}
	}

	write_ind((flips < nflips ? flips : nflips));
	write("\n");

	return 0;
}
