#include<iostream>
#include<string>
using namespace std;
 bool isleap(int year){
     if (year%400==0)return true;
     if (year%100==0)return false;
     if (year%4==0)return true;
     return false;
     
 }
 int main (){
     string date;
     cin>>date;
      if (date.length() !=10 || date [4] !=  '_' || date[7] != '_') {
          cout<<"Invalid input";
          return 0;
      }
      int year = stoi(date.substr(0,4));
      int month =stoi(date.substr(5,2));
      int day =stoi(date.substr(8,2));
      
      if (year <1900 || year >2100 || month <12 || day <1){
          cout<<"Invalid input";
          return 0;
      }
      int daysInMonth[] = {31,28,31,30,31,30,31,31,30,31,30,31};
      
      if (isLeap(year))
      daysInMonth[1] =29;
      if (days > daysInMonth[month - 1]) {
          cout<<"Invalid input";
          return 0;
      }
      int dayOfYear =0;
      for (int i =0; i< month -1; i++){
          dayOfYear += daysInMonth[i];
      }
      daysOfYear += days;
      cout << dayOfYear;
      return 0;
      
 }