#include <iostream>

using namespace std;

int main() {
	int h, m;
	int tH, tM, nTime;

	cin >> h >> m;
	if (h == 0)	h = 24;

	tH = h * 60;
	tM = tH + m;
	nTime = tM - 45;

	cout << nTime / 60 << " " << nTime % 60;

	return 0;
}