#include <iostream>
using namespace std;

int main()
{
	int n;
	while(cin >> n,n)
	{
		int retu[13],mae[13];
		for (int i = 0; i < n; i++)
		{
			cin >> retu[i];
			mae[i] = retu[i];
		}
		int ans = 0;
		while(1)
		{
			int kazu[13] = {};
			for (int i = 0; i < n; i++)
			{
				mae[i] = retu[i];
				++kazu[retu[i]];
			}
			for (int i = 0; i < n; i++)
				retu[i] = kazu[retu[i]];
			int h = 0;
			for (int i = 0; i < n; i++)
				h += (mae[i] == retu[i]);
			if(h == n)
			{
				cout << ans << endl;
				break;
			}
			++ans;
		}
	}
}