#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;

int k;
ll res;

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    scanf("%d", &k);
    for (ll i = 1; i <= k; ++i) {
        for (ll j = 1; i * j <= k; ++j) {
            res += k / (i * j);
        }
    }
    printf("%lld\n", res);
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void run(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const int N=2e5+5;
int dp[19][3][19],n;
bool vis[19][3][19];
string s;
int sol(int i,int sum,int erased){
    sum%=3;
    if(i==n){
        return !(sum==0&&erased!=n)*1e9;
    }
    int &ret=dp[i][sum][erased];
    if(vis[i][sum][erased]==1)
        return ret;
    vis[i][sum][erased]=1;
    ret=1e9;
    ret=min(sol(i+1,sum,erased+1)+1,sol(i+1,sum+s[i]-'0',erased));
    return ret;
}
void solve(){
memset(dp,-1,sizeof dp);
cin>>s;
n=s.size();
cout<<(sol(0,0,0)>=1e9 ? -1:sol(0,0,0));
}
int main()
{
    run();
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}
