#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
cin.tie(0);
std::ios::sync_with_stdio(false);
int k;
vector<int> arr;
vector<int> temp;
while (cin >> k && k != 0)
{
int t;
int p;
int address;
int m = 1;
int sum = 0;
int stop = 0;
temp.clear();
arr.clear();
for (int i = 0; i <= 2 * k; i++)
{
temp.push_back(i);
}
for (int i = 0; i <= k; i++)
{
stop += i;
}
while (sum != stop)
{
p = 2 * k;
t = 0;
sum = 0;
address = 0;
arr = temp;
while (p > k)
{
if (t == m)
{
address += t;
while (address > arr.size() - 1)
{
address -= arr.size() - 1;
}
arr.erase(arr.begin() + address);
if (address == 1)
{
address = arr.size() - 1;
}
else
{
address--;
}
t = 0;
p--;
}
else
{
t++;
}
}
for (auto i = arr.begin(); i != arr.end(); ++i)
{
sum += *i;
}
m++;
}
cout << m - 1 << '\n';
}
return 0;
}