#include <bits/stdc++.h>
using namespace std;

long long multi(string x){
  long long a,i,minus,multiple=10000,n=x.size();
  a=0;
  if(x[0]=='-'){
    minus=-1;
    i=1;
  }else{
    minus=1;
    i=0;
  }
  while(i<n){
    if(x[i]=='.'){
      i++; continue;
    }else{
      a=a*10+(x[i]-'0');
      i++;
    }
  }
  
  if(n>=2 && x[n-2]=='.'){
    multiple=1000;
  }else if(n>=3 && x[n-3]=='.'){
    multiple=100;
  }else if(n>=4 && x[n-4]=='.'){
    multiple=10;
  }else if(n>=5 && x[n-5]=='.'){
    multiple=1;
  }else{
    multiple=10000;
  }
  return minus*a*multiple; 
}

int main() {
	long long n,i,j,a,b,c,cur,lef,rig,ans;
	string x,y,r;
	cin >> x >> y >> r;
	
   
    a=multi(x); b=multi(y); c=multi(r);
    a=abs(a); b=abs(b);
	//a=x*10000; b=y*10000; c=r*10000;
    //cout << a <<' '<< b << ' '<<  c << endl;
  /*
	lef=((a-c+10000000000+9999)/10000)*10000-10000000000;
	rig=((a+c+10000000000)/10000)*10000-10000000000;
  
	
	ans=0;
	for(i=lef; i<=rig; i+=10000){
		cur=floor(sqrt(c*c-abs(a-i)*abs(a-i)));
		//cout << i << ' ' << cur << endl;
		ans+=((b+cur+10000000000)/10000)-((b-cur+10000000000+9999)/10000)+1;
	}
	cout << ans << endl;
    */
  ans=0;
  long long ok,ng,mid,res;
    for(i=-300000; i<=300000; i++){
      if(abs(i*10000-a)<=c){
        res=c*c-abs(i*10000-a)*abs(i*10000-a);
        ok=-1; ng=10000000000;
        while(ng-ok>1){
          mid=(ok+ng)/2;
          if(mid*mid<=res){
            ok=mid;
          }else{
            ng=mid;
          }
        }

        ans+=(ok+b+10000000000)/10000-(b-ng+10000000000)/10000;
      }
    }
    cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);}
template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

int main() {
    ll N, M; cin >> N >> M;
    vector<vector<ll>> a(N,vector<ll>(N,inf));
    rep(i,M) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        chmin(a[x][y],z);
    }

    vector<vector<ll>> dp(N+1,vector<ll>(1<<N));
    dp[0][0] = 1;
    rep(i,N) {
        rep(bit,1<<N) {
            if (dp[i][bit]==0) continue;
            rep(j,N) {
                if ((bit>>j)&1) continue;
                ll nbit = bit | (1<<j);
                bool ng = false;
                ll cnt = 0;
                rep(k,N) {
                    if ((nbit>>k)&1) cnt++;
                    if (cnt>a[i][k]) ng = true;
                }
                if (ng) continue;
                dp[i+1][nbit] += dp[i][bit];
            }
        }
    }
    ll X = (1<<N)-1;
    ll ans = dp[N][X];
    Cout(ans);
}