#include <bits/stdc++.h>
using namespace std;
int m[105] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dd, mm, yy;
int bd, bm, by;
bool ok(int a, int b, int c) {
  if (m[b] >= a || (b == 2 && c % 4 == 0 && m[b] + 1 >= a)) {
    if (yy - c > 18) return true;
    if (yy - c == 18 && (mm > b || (mm == b && dd >= a))) return true;
  }
  return false;
}
int main(void) {
  scanf("%d.%d.%d", &dd, &mm, &yy);
  scanf("%d.%d.%d", &bd, &bm, &by);
  int a = bd;
  int b = bm;
  int c = by;
  bool f = false;
  if (ok(a, b, c)) {
    cout << "YES" << endl;
    return 0;
  }
  if (ok(a, c, b)) {
    cout << "YES" << endl;
    return 0;
  }
  swap(a, b);
  if (ok(a, b, c)) {
    cout << "YES" << endl;
    return 0;
  }
  if (ok(a, c, b)) {
    cout << "YES" << endl;
    return 0;
  }
  swap(a, b);
  swap(a, c);
  if (ok(a, b, c)) {
    cout << "YES" << endl;
    return 0;
  }
  if (ok(a, c, b)) {
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}
