Example

Input

20


Output

4
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <string>
#include <set>
#include <queue>
#include <cmath>
using namespace std;
typedef long long LL;
const int N = 1005;

vector<LL> ver[15];
LL f[2][140][20000][2];

char str[20];

int main() {
    ver[0].push_back(1);
    for (int i = 0; i < 14; ++i) {
        for (int j = 0; j < ver[i].size(); ++j) {
            for (int k = 1; k <= 10; ++k)
                ver[i + 1].push_back(ver[i][j] * k);
        }
        sort(ver[i + 1].begin(), ver[i + 1].end());
        ver[i + 1].erase(unique(ver[i + 1].begin(), ver[i + 1].end()), ver[i + 1].end());
    }
    gets(str + 1);
    int n = strlen(str + 1);
    reverse(str + 1, str + 1 + n);
    int S = 0;
    LL P = 1;
    for (int i = 1; i <= n; ++i) {
        int tmp = str[i] - '0';
        S += tmp;
        P *= tmp + 1;
    }
    int cur = 0, nex = 1;
    f[cur][0][0][1] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= S; ++j)
            for (int k = 0; k < ver[i].size(); ++k)
                for (int l = 0; l < 2; ++l)
                    f[nex][j][k][l] = 0;
        int ch = str[i] - '0';
        for (int j = 0; j <= S; ++j)
            for (int k = 0; k < ver[i - 1].size(); ++k)
                for (int l = 0; l < 2; ++l)
                    if (f[cur][j][k][l]) {
                        for (int p = 0; p < 10; ++p) {
                            if (j + p > S) continue;
                            int j1 = j + p;
                            int k1 = lower_bound(ver[i].begin(), ver[i].end(), ver[i - 1][k] * (p + 1)) - ver[i].begin();
                            int l1 = l;
                            if (p > ch) l1 = 1;
                            if (p < ch) l1 = 0;
                            f[nex][j1][k1][l1] += f[cur][j][k][l];
                        }
                    }
        swap(cur, nex);
    }
    LL ans = 0;
    for (int j = 0; j <= S; ++j)
        for (int k = 0; k < ver[n].size(); ++k)
            for (int l = 0; l < 2; ++l) {
                if (j != S) {
                    ans += f[cur][j][k][l];
                }
                else {
                    if (ver[n][k] != P) {
                        if (ver[n][k] < P) ans += f[cur][j][k][l];
                    }
                    else if (l == 0) ans += f[cur][j][k][l];
                }
            }
    cout << ans << endl;
}