#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>  
#include <queue>
#include <iostream>
#include <climits> 

using namespace std;

#include <iomanip>

bool is239(int hour, int minute) 
{
    string t1 = to_string(hour);
    if (hour < 10) t1 = "0" + t1;
    
    string t2 = to_string(minute);
    if (minute < 10) t2 = "0" + t2; 
    
    string t = t1 + t2;
    
    return (t[1] == '2' && t[2] == '3' && t[3] == '9') || // X2:39
           (t[0] == '2' && (t[1] == '0' || t[1] == '2' || t[1] == '3') && t[2] == '3' && t[3] == '9') || // 2X:39
           (t[0] == '2' && t[1] == '3' && (t[2] == '0' || t[2] == '3' || t[2] == '9') && t[3] == '9') || // 23:X9
           (t[0] == '2' && t[1] == '3' && t[2] == '9'); // 23:9X
}

int main() 
{
    int H, M;
    cin >> H;
    cin >> M;

    int count = 0;

    for (int hour = 0; hour < H; ++hour)
        for (int minute = 0; minute < M; ++minute)
            if (is239(hour, minute)) 
                count++;
            
    cout << count;
    
    return 0;
}