#include <bits/stdc++.h>
using namespace std;
// it times out
bool f( int a,int b){
	return a>b;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	vector<int> v,p;
	for(int i=0;i<=1000000;i++){
		int r=(i*41+78)%1997;
		v.push_back(r);
		p.push_back(r);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	sort(p.begin(),p.end(),f);
	int l=0;
	for(int i=0;i<=1000000;i++){
		if(v[i]==p[i]){
		l++;
		}
	}
	cout<<l;
}