#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pair<long long, long long> = pair<long long, long long>;
using vc = vector<char>;
using vvc = vector<vc>;
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
set<long long> ans;
void dfs(string s) {
  long long k = stol(s);
  if (k > 1e9) return;
  ans.insert(k);
  dfs(s + '3');
  dfs(s + '5');
  dfs(s + '7');
  return;
}
int main() {
  long long n;
  cin >> n;
  dfs("3");
  string h = "6";
  cout << (h + '9') << endl;
  long long cu = 0;
  for (auto p : ans) {
    set<char> j;
    string d = to_string(p);
    for (long long i = 0; i < ((long long)(d).size()); i++) j.insert(d[i]);
    if (p <= n && (long long)(j).size() == 3) cu++;
  }
  cout << (cu) << endl;
}
