#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	vector<int> a[3];
	int n, m;
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		a[u].push_back(v);
	}
	int b[3];
	for (int i = 1; i <= 3; i++)
	{
		for (int j = 0; j < a[i].size(); j++)
		{
			b[i-1] = a[i][j];
			if (a[i][j] < b[0]) { b[i-1] = a[i][j]; }
		}
	}
	int n = b[0] + b[1] * 10 + b[2] * 100;
	cout << n << '\n';
}