# 建立一個年號對應的起始西元年份字典
year_map = {
"ShunZhi": 1644,
"KangXi": 1662,
"YongZheng": 1723,
"QianLong": 1736,
"JiaQing": 1796,
"DaoGuang": 1821,
"XianFeng": 1851,
"TongZhi": 1862,
"GuangXu": 1875,
"XuanTong": 1909
}
# 讀取輸入
era, year = input().split()
year = int(year)
# 根據年號和年份計算西元年份
start_year = year_map[era]
western_year = start_year + (year - 1)
# 輸出結果
print(western_year)
# 建立一個年號對應的起始西元年份字典
year_map = {
"ShunZhi": 1644,
"KangXi": 1662,
"YongZheng": 1723,
"QianLong": 1736,
"JiaQing": 1796,
"DaoGuang": 1821,
"XianFeng": 1851,
"TongZhi": 1862,
"GuangXu": 1875,
"XuanTong": 1909
}
# 讀取輸入
era, year = input().split()
year = int(year)
# 根據年號和年份計算西元年份
start_year = year_map[era]
western_year = start_year + (year - 1)
# 輸出結果
print(western_year)