#include <iostream>
using namespace std;

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