#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i < b; i++)
#define rrep(i,a,b) for (int i = a - 1; i >= b; i--)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define pvec(a) for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << '\n'
#define wt(a) cout << a << '\n'
using namespace std;
using ll = long long;
template<class T, class U>bool chmin(T& a, U b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U>bool chmax(T& a, U b) {if (a < b) {a = b; return 1;} return 0;}

//-------------------------------------------------------------------------------------//

// ans = mod_pow(a, b, (ll)MOD);
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


int main() {
    ll A, B, C;
    cin >> A >> B >> C;

    ll a = mod_pow(B, C, (ll)4);
    int memo[10][4];
    rep (i, 0, 10) {
        memo[i][0] = i;
        memo[i][1] = memo[i][0] * i % 10;
        memo[i][2] = memo[i][1] * i % 10;
        memo[i][3] = memo[i][2] * i % 10;
    }

    if (a == 0) cout << memo[A % 10][3] << endl;
    else if (a == 1) cout << memo[A % 10][0] << endl;
    else if (a == 2) cout << memo[A % 10][1] << endl;
    else cout << memo[A % 10][2] << endl;
    return 0;
}

/* {{{ */
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <prettyprint.hpp>
#define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl
#else
#define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl
#endif
using ll = long long;
template <class T> using vec = vector<T>;
#define endl "\n"
#define INF (int)1e9
#define LINF (long long)1e12
#define MOD (int)1e9+7
#define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++)
#define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--)
#define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define each(e, c) for (auto &e: c)
#define all(v) begin(v), end(v)
#define popcount __builtin_popcount
template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; }
template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; }
void keep_my_fingers_crossed()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}
/* }}} */

int main()
{
  keep_my_fingers_crossed();
  ll n, w;
  cin >> n >> w;
  vec<pair<ll, ll>> a;
  rep(i, n)
  {
    ll s, t, p;
    cin >> s >> t >> p;
    a.push_back({ s, p });
    a.push_back({ t, -p });
  }
  sort(all(a), [&](auto x, auto y){ return x.first < y.first; });

  map<ll, ll> usage;
  ll total = 0;
  for (auto [t, p]: a)
  {
    total += p;
    usage[t] = total;
  }

  for (auto [key, val]: usage)
  {
    if (val > w)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

