#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  int commaCnt = 1;

  bool exist = false;
  if (n >= 1000){
    exist = true;
  }
  while(exist){
    ll maxNum = pow(1000, commaCnt + 1) - 1;
    if(n > maxNum){
      ans += commaCnt * (maxNum - pow(1000, commaCnt) + 1);
    } else {
      ans += commaCnt * (n - pow(1000, commaCnt) + 1);
      exist = false;
    }
    commaCnt++;
  }
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

int64_t eval(array<int, 5>& assign, vector<array<int64_t, 32>>& vals)
{
	int64_t ans = INT64_MAX;
	
	FOR_LT(i, 0, 3) {
		int64_t s = 0;
		FOR_LT(j, 0, 5) {
			if (assign[j] == i) s += (1 << j);
		}
		if (s == 0) continue;

		int64_t ca = 0;
		FOR_LT(k, 0, vals.size()) {
			ca = max(ca, vals[k][s]);
		}
		ans = min(ans, ca);
	}
	return ans;
}

int64_t solve(int i, array<int, 5>& assign, vector<array<int64_t, 32>>& vals)
{
	if (i == 5) {
		return eval(assign, vals);
	}

	int64_t ans = 0;
	FOR_LT(j, 0, 3) {
		assign[i] = j;
		ans = max(ans, solve(i + 1, assign, vals));
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int64_t n; cin >> n;
	vector<array<int64_t, 5>> as(n);
	FOR_LT(i, 0, n) {
		FOR_LT(j, 0, 5) {
			cin >> as[i][j];
		}
	}

	int64_t mv = 1;
	REP(5) mv *= 5;
	vector<array<int64_t, 32>> vals(n);
	FOR_LT(i, 0, n) {
		FOR_LT(j, 0, 32) {
			int64_t c = INT_MAX;
			FOR_LT(k, 0, 5) {
				if (j & (1 << k)) c = min(c, as[i][k]);
			}
			vals[i][j] = c;
		}
	}

	array<int, 5> assign;
	assign[0] = 0;
	cout << solve(1, assign, vals) << endl;


	return 0;
}