#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
char input[1000];
char temp[1000];
char temp2[1000];
char temp3[1000];
char champernowne[1000000];

void PrintChampernowne(int index, int len) {
  REP(i, len) {
    putchar(champernowne[index + i - 1]);
  }
  puts("");
}

ll Convert(pair<ll, ll> ans) {
  //cout << ans.first << " " << ans.second << endl;
  ll ret = ans.second + 1;
  ll base = 1;
  ll cnt = 1;
  ans.first--;
  while (true) {
    if (base * 10 <= ans.first) {
      ret += cnt * base * 9;
    } else {
      ret += cnt * (ans.first - base + 1);
      break;
    }
    cnt++;
    base *= 10;
  }
  return ret;
}

void Plus(char *str) {
  (*str)++;
  if (*str > '9') { *str = '0'; Plus(str - 1); }
}

int main() {
  FOREQ(i, 1, 10000) {
    sprintf(champernowne + strlen(champernowne), "%d", i);
  }
  while (scanf("%s", input), input[0] != '#') {
    pair<ll, ll> ans(1LL << 60, 1LL << 60);
    n = strlen(input);
    // one
    if (n < 17) {
      if (input[0] == '0') {
        sprintf(temp, "1%s", input);
        ans = min(ans, make_pair(atoll(temp), 1LL));
      } else {
        ans = min(ans, make_pair(atoll(input), 0LL));
      }
    }
    // two
    if (n < 34) {
      FOREQ(i, 1, n) {
        if (input[i] == '0') { continue; }
        int start = 100;
        MEMSET(temp2, '0');
        memcpy(temp2 + start, input, i);
        temp2[start + i] = 0;
        sprintf(temp, "%s", temp2 + start);
        Plus(temp2 + start + i - 1);
        if (temp2[start - 1] == '1') { start--; }
        if ((int)strlen(temp) >= n) { continue; }
        FOREQ(j, 0, i + 1) {
          if (i + j > n) { continue; }
          memcpy(temp2 + start - (n - i - j), input + i, n - i - j);
          sprintf(temp + i, "%s", temp2 + start - (n - i - j));
          temp[n] = '\0';
          if (strcmp(input, temp) == 0) {
            ll v = atoll(temp2 + start - (n - i - j)) - 1;
            sprintf(temp3, "%lld", v);
            ll len = strlen(temp3);
            if (len >= 17) { continue; }
            ll offset = len - i;
            //cout << i << " " << j << " " << v << " " << offset << endl;
            ans = min(ans, make_pair(v, offset));
          }
        }
      }
    }
    // more than
    FOREQ(i, 1, n) {
      FOREQ(j, 1, n) {
        memcpy(temp, input + j, i);
        temp[i] = '\0';
        ll start = atoll(temp) - 1;
        if (start <= 0) { continue; }
        ll v = start;
        sprintf(temp2, "%lld", v);
        int len = strlen(temp2);
        if (len < j) { continue; }
        ll offset = len - j;
        sprintf(temp, "%s", temp2 + offset);
        int cnt = 1;
        while ((int)strlen(temp) < n) {
          v++;
          cnt++;
          sprintf(temp + strlen(temp), "%lld", v);
        }
        if (cnt < 3) { continue; }
        temp[n] = 0;
        if (strcmp(input, temp) == 0) {
          ans = min(ans, make_pair(start, offset));
        }
      }
    }
    // edge
    FOREQ(i, 1, 17) {
      REP(offset, i) {
        ll start = 1;
        REP(j, i) { start *= 10; }
        start--;
        REP(j, i - offset) {
          temp[j] = '9';
        }
        temp[i - offset] = '\0';
        ll v = start;
        while ((int)strlen(temp) < n) {
          v++;
          sprintf(temp + strlen(temp), "%lld", v);
        }
        temp[n] = 0;
        if (strcmp(temp, input) == 0) {
          ans = min(ans, make_pair(start, (ll)offset));
        }
      }
    }
    //PrintChampernowne(2887, 10);
    printf("%lld\n", Convert(ans));
    //cout << input << endl;
    //PrintChampernowne(Convert(ans), n);
  }
}

Measured memory_bytes: 940