#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
bool is_valid(vector<int> v) {
  if (v[1] > 12) return false;
  int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if (v[0] % 4 == 0) m[1]++;
  return v[2] <= m[v[1] - 1];
}
int main() {
  vector<int> y(3), v(3);
  scanf("%d.%d.%d", &y[0], &y[1], &y[2]);
  scanf("%d.%d.%d", &v[0], &v[1], &v[2]);
  sort(v.begin(), v.end());
  vector<int> maxm(3, 1000);
  do {
    if (is_valid(v)) {
      maxm = min(maxm, v);
    }
  } while (next_permutation(v.begin(), v.end()));
  v = maxm;
  reverse(v.begin(), v.end());
  if (v[2] < y[2] - 18 || (v[2] == y[2] - 18 && v[1] < y[1]) ||
      (v[2] == y[2] - 18 && v[1] == y[1] && v[0] <= y[0]))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
