#include <iostream>
using namespace std;

int main() {
	// your code goes here
	
	int sum=0;
	int init=10000000;
	int end=99999999;
	int *d=0;
	
	for (int i=init; i<=end; i++) {
		int j=i;
		d = new int[10];
		while (j>0) {
			d[j%10]++;
			j/=10;
		}
		bool repeat = false;
		for (int k=0;k<=9;k++) {
			if (d[k]>=2) {
				repeat=true;
			}
		}
		if (!repeat) {
			if (i%3==0)
				sum++;
		}
		delete[] d;
	}
	
	cout << sum;
	return 0;
}