#include <bits/stdc++.h>
using namespace std;
const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
const double eps = 1e-9;
template <class T>
void print(T const &x) {
  ostringstream os;
  os << x;
  cout << os.str() << endl;
}
template <class T>
void print(vector<T> const &v) {
  ostringstream os;
  for (int i = 0; i < v.size(); ++i) {
    if (i) os << ' ';
    os << v[i];
  }
  cout << os.str() << endl;
}
template <class T>
void print(vector<vector<T> > const &v) {
  ostringstream os;
  for (int i = 0; i < v.size(); ++i) {
    for (int j = 0; j < v[i].size(); ++j) {
      if (j) os << ' ';
      os << v[i][j];
    }
    os << endl;
  }
  cout << os.str() << endl;
}
template <class T>
void print(valarray<T> const &v) {
  ostringstream os;
  for (int i = 0; i < v.size(); ++i) {
    if (i) os << ' ';
    os << v[i];
  }
  cout << os.str() << endl;
}
template <class T>
int sz(const T &c) {
  return (int)c.size();
}
template <class T>
void srt(T &c) {
  std::sort(c.begin(), c.end());
}
template <class T>
void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T, class U>
T cast(U x) {
  ostringstream os;
  os << x;
  T res;
  istringstream is(os.str());
  is >> res;
  return res;
}
template <class T>
vector<T> split(string s, string x = " ") {
  vector<T> res;
  for (int i = 0; i < s.size(); i++) {
    string a;
    while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++];
    if (!a.empty()) res.push_back(cast<T>(a));
  }
  return res;
}
template <class T>
bool inside(T r, T c, T R, T C) {
  return r >= 0 && r < R && c >= 0 && c < C;
}
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool check(vector<int> x, int d1, int m1, int y1) {
  days[1] = y1 % 4 == 0 ? 29 : 28;
  if (m1 > 12 || d1 > days[m1 - 1]) return false;
  int d2 = x[0];
  int m2 = x[1];
  int y2 = x[2];
  int d = d1;
  int m = m1;
  int y = y1;
  int age = -1;
  while (1) {
    if (y > y2 || y == y2 && m > m2 || y == y2 && m == m2 && d > d2) break;
    if (m == m1 && d == d1 ||
        m1 == 2 && d1 == 29 && y % 4 && m == 3 && d == 1) {
      ++age;
    }
    ++d;
    if (d > days[m - 1]) {
      d = 1;
      ++m;
      if (m > 12) {
        m = 1;
        ++y;
      }
    }
  }
  return age >= 18;
}
int main(int argc, char *argv[]) {
  string a, b;
  cin >> a >> b;
  vector<int> x = split<int>(a, ".");
  vector<int> y = split<int>(b, ".");
  bool b1 = check(x, y[0], y[1], y[2]);
  bool b2 = check(x, y[0], y[2], y[1]);
  bool b3 = check(x, y[1], y[0], y[2]);
  bool b4 = check(x, y[1], y[2], y[0]);
  bool b5 = check(x, y[2], y[0], y[1]);
  bool b6 = check(x, y[2], y[1], y[0]);
  if (b1 || b2 || b3 || b4 || b5 || b6) {
    cout << "YES" << endl;
  } else
    cout << "NO" << endl;
  return 0;
}
