#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class FixedNumberOfDigits { public:
	long long sum(int start, int step, long long numberOfDigits)
	{
		return solve(start, step, numberOfDigits);
	}

	LL solve(LL s, LL inc, LL nd) {
		LL next = 10;
		int w = 1;
		while (next <= s) {
			next *= 10;
			w += 1;
		}
		next = (next - s + inc - 1) / inc * inc + s;
		LL k = (next - s) / inc;
		if (k * w >= nd) {
			LL q = nd / w;
			LL r = nd % w;
			if (r == 0) q -= 1, r += w;

			stringstream ss;
			ss << (s + inc*q);
			stringstream ss2;
			ss2 << ss.str().substr(0, int(r));
			LL ans;
			ss2 >> ans;
			return ans;
		}
		return solve(next, inc, nd - k*w);
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, FixedNumberOfDigits().sum(start, step, numberOfDigits));}
int main(){

CASE(0)
	int start = 47; 
	int step = 10; 
	long long numberOfDigits = 7LL; 
	long long _ = 7LL; 
END
CASE(1)
	int start = 98; 
	int step = 1; 
	long long numberOfDigits = 10LL; 
	long long _ = 101LL; 
END
CASE(2)
	int start = 0; 
	int step = 1; 
	long long numberOfDigits = 7LL; 
	long long _ = 6LL; 
END
CASE(3)
	int start = 123456789; 
	int step = 10; 
	long long numberOfDigits = 5LL; 
	long long _ = 12345LL; 
END
CASE(4)
	int start = 123456789; 
	int step = 10; 
	long long numberOfDigits = 17LL; 
	long long _ = 12345679LL; 
END
CASE(5)
	int start = 0; 
	int step = 1; 
	long long numberOfDigits = 15LL; 
	long long _ = 1LL; 
END
CASE(6)
int start = 314;
int step = 11;
long long numberOfDigits = 9LL;
long long _ = 336LL;
END
CASE(6)
int start = 314;
int step = 11;
long long numberOfDigits = 192LL;
long long _ = 100LL;
END
CASE(6)
int start = 1;
int step = 612;
long long numberOfDigits = 10LL;
long long _ = 18LL;
END
}
// END CUT HERE
