#include <iostream>
#include <string>

using namespace std;
string s , ss;
int x , cnt , h , m;

bool chck(){
    if(h/10==7 || h%10==7 || m/10==7 || m%10==7){
        return 1;
    }else
        return 0;
}

void tabe(){
    if(m>=x){
        m-=x;
    }else {
        int t=x-m;
        m=60-t;
        if(h>=1){
            h--;
        }else{
            h=23;
        }
    }
}

int main()
{
    cin>>x>>s>>ss;
    h=int(s[0]-'0')*10+int(s[1]-'0');
    m=int(ss[0]-'0')*10+int(ss[1]-'0');
    while(chck()==0){
        tabe();
        cnt++;
    }
    cout<<cnt;
    return 0;
}

#include <iostream>

using namespace std;

int x, h, m, ans = 0;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> x;
	cin >> h >> m;

	int time = (h * 60) + m;

	bool find_ans = true;

	while (find_ans)
	{
		int hh, m1, m2;

		hh = (time / 60) % 10;
		m1 = (time % 60) / 10;
		m2 = (time % 60) % 10;

		if (hh == 7 || m1 == 7 || m2 == 7)
		{
			cout << ans;
			find_ans = false;
		}

		ans++;

		time -= x;

		if (time < 0)
		{
			time += 1440;
		}
	}
}

#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<deque>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#include<fstream>
#include<functional>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define N 200005
#define mod 1000000007
#define ll long long
#define inf 0x7fffffff
ll a[N],b[N];
int ans[N];
ll t[N<<2],lazy[N<<2];
//int lu[N<<2],ru[N<<2];

int main()
{
	int x;
	int hh,mm;
	cin>>x>>hh>>mm;
	int ans = 0;
	int ti = hh*60+mm;
	while(1){
		int t2 = ti-ans*x;
		while(t2<0)
			t2+=1440;
		hh = t2/60;
		mm = t2%60;
		if(hh%10==7||mm%10==7){
			cout<<ans<<endl;
			return 0;
		}
		ans++;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int x, h, m, ans;
    cin >> x >> h >> m;
    if(h%10==7 || m%10==7){
        ans = 0;
    }
    else{
        for(int i=1;;i++){
            m-=x;
            if(m<0){
               m=60+m;
               h--;
            }
            if(h<0) h=23;
            if(h%10==7 || m%10==7){
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif

    int x;
    int h,m;
    cin >> x >> h >> m;
    int count=0;
    while(h%10!=7 && m%10!=7)
    {
    	m=m-x;
    	if(m<0)
    	{
    		m=m+60;
    	    h--;
    	}
    	if(h<0)
    	{
    		h=23;
    	}
    	count++;
    }
    cout<<count<<endl;

	return 0;
}

#include<iostream>
using namespace std;
int fun(int a,int b)
{
	if(a%10==7||(a/10)==7||b%10==7||b/10==7)
	return 1;
	else
	return 0;
}
int main()
{
	int x,h,m,count=0;
	cin>>x>>h>>m;
	while(1)
	{
			  if(fun(h,m))

	{

		cout<<count<<endl;
		break;
	}
		for(int i=0;i<x;i++)
		{
			if(h==0&&m==0)
			{
				h=23;
				m=59;
			}
	    else if(m==00)
		{
			h=h-1;
			m=59;
		}

else
		m=m-1;
		//cout<<h<<" "<<m<<endl;
}
     count++;

	}
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int x;
    cin>>x;

    string sh,sm;
    cin>>sh>>sm;

    if (sh[0]=='7' || sh[1]=='7' || sm[0]=='7' || sm[1]=='7')
    {
        cout<<0;
        return 0;
    }

    int hh;
    stringstream ss;
    ss<<sh;
    ss>>hh;

        int mm;
    stringstream sss;
    sss<<sm;
    sss>>mm;

    int z=0;
    string ssh;
    for (int i=mm-x;;i-=x)
    {
        z++;
        if (hh<0)
        {
            hh=23;
        }
        if (i<0)
        {
            i+=60;
            hh--;

            if ((hh-7)%5==0 && (hh-7)%10==0)
            {
                cout<<z;
                return 0;
            }
        }
        if ((i-7)%5==0 && (i-7)%10==0)
        {
            cout<<z;
            return 0;
        }
    }

return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,c=0;
    cin>>t;
    int x,y;
    cin>>x>>y;
    while(1)
    {
        if(y%10==7||x%10==7)
        {
            break;
        }
        if(y>=t)
        {
            y-=t;
            c++;
        }
        else
        {
            if(x>0)
            {
                y+=60;
                x--;
                y-=t;
                c++;
            }
            else
            {
                x+=23;
                y+=60;
            }
        }
    }
    cout<<c<<endl;

    return 0;
}

#include<stdio.h>
#include<math.h>
int max(int a,int b){
	if(a>b) return b;
	 else return a;
}
int main(){
	long  n,hh,mm,num=0;
	scanf("%ld %ld %ld",&n,&hh,&mm);
	while(hh%10!=7&&hh/10!=7&&mm%10!=7&&mm/10!=7){
	  if(mm>=n){
	  	mm-=n;num++;
	  }
	   else{
	       mm = mm + 60 - n;
	       num++;
	   	   if(hh==0) hh=23;
	   	    else hh--;
	   }
	}
	printf("%d",num);
	return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;
const int mx=2e5+10;

int x,a,b;
char s1[5],s2[5];

int main()
{
	a=b=0;
	scanf("%d",&x);
	getchar();
	scanf("%s %s",s1,s2);
	int l1=strlen(s1);
	for(int i=0;i<l1;i++)
	 a=a*10+s1[i]-'0';
	int l2=strlen(s2);
	for(int i=0;i<l2;i++)
	 b=b*10+s2[i]-'0';
	int sum=0;
	while(b%10!=7&&a%10!=7)
	{
		sum++;
		b-=x;
		if(b<0)
		{
			b+=60;
			a--;
			if(a<0)
			a=23;
		}
	}
	printf("%d\n",sum);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define memset(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 0x3f3f3f3f
const int maxn=1e5+10;

int main()
{
    int x,h,m,cnt=0;
    scanf("%d %d %d",&x,&h,&m);
    if(m % 10 == 7 || h%10 == 7)
        printf("0\n");
    else{
        while(1){
            if(m < x){
              h--,m = m + 60 -x;
              if(h < 0)
                h+=24;
            }
            else
              m = m - x;
            cnt++;
            if(m % 10 == 7 || h % 10 ==7)
            {
                printf("%d\n",cnt);
                break;
            }
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
inline int read(int&x) {
    int data=0,w=1;
    char ch=0;
    while(ch!='-' && (ch<'0' || ch>'9')) ch=getchar();
    if(ch=='-') w=-1,ch=getchar();
    while(ch>='0' && ch<='9') data=data*10+ch-'0',ch=getchar();
    return x=data*w;
}
inline void write(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int main(void)
{
    int a,b,c,sum=0,xx=0;
    read(a),read(b),read(c);
    if (b%10==7||c%10==7){
        printf("0");
        exit(0);
    }
    while(1){
    	if (b%10==7||c%10==7) {
          write(sum);
          exit(0);
    }
		if (c-a<0){
            c+=60;
			c-=a;
            if (b==0) b+=23;
		    else b--;
        }
        else {
        c-=a;
    }
        sum++;
    }
}

#include<iostream>
using namespace std;
int t,hh,mm,ans;
int main(){
	cin>>t>>hh>>mm;
	if(hh%10==7||mm%10==7){
		cout<<0;
		return 0;
	}while(1){
		mm-=t;
		if(mm<0){
			hh--;
			mm+=60;
			if(hh<0)hh+=24;
		}ans++;
		if(hh%10==7||mm%10==7){
			cout<<ans;
			return 0;
		}
	}
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,hh,mm,total=0;
	scanf("%d%d%d",&n,&hh,&mm);
	while((!(!(hh%10-7)))&&(!(!(mm%10-7))))
	{
		if(mm<n)
		{
			if(!hh)
			{
				hh+=24;
			}
			hh--;
			mm+=60;
		}
		mm-=n;
		total++;
	}
	printf("%d",total);
	putchar(10);
	return 0;
}

#include<iostream>
#pragma warning(disable:4996);

using namespace std;
int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int x, ft, st, s = 0;
	scanf("%d%d%d", &x, &ft, &st);
	while (st % 10 != 7 && ft % 10 != 7) {
		st -= x;
		s += 1;
		if (st < 0) {
			st += 60;
			ft -= 1;
			if (ft < 0) {
				ft += 24;
			}
		}
	}
	printf("%d", s);
	return 0;
}

/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
typedef long double ld;
const ll inf=(1LL<<60)-1;
const ll mxn=1e5;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
vector<ll>adj[10000+5];
ll col[10000+5],vis[10000+5],cnt=1;
void dfs(ll n)
{
    vis[n]=1;
    //cout<<n<<endl;
    for(auto child:adj[n])
    {
        //cout<<child<<endl;
        if(!vis[child])
        {
            if(col[n]!=col[child])
                cnt++;
            dfs(child);
        }

    }
}
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll x,h,m,cnt=0;
    cin>>x>>h>>m;
    ll t=h*60+m;
    while(1)
    {
       h=t/60,m=t%60;
       if(h/10==7 || h%10==7 || m/10==7 || m%10==7)
       {
           cout<<cnt<<endl;
           return;
       }
       cnt++;
       t=(t-x+1440)%1440;
    }

}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}

#define fr(i,n) for(int i=0;i<n;i++)
#define fi(i,m,n) for(int i=m;i<=n;i++)
#define ll long long
#include <bits/stdc++.h>

using namespace std;

int main()
{

    short int  h2,m2,x,cb;
    scanf("%hd%hd%hd",&x,&h2,&m2);

    cb=0;

    while(h2%10!=7&&m2%10!=7)
    {//cout<<h2<<" "<<m2<<" "<<cb<<endl;
        m2-=x; cb++;
        if(m2<0){h2--;m2=60+m2;}

    if(h2<0)h2=(h2+24)%24;

    //if(cb>2400)break;
    }
    printf("%hd",cb);

}

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N = 500100;
const int M = 500010;
const int INF = 0x3f3f3f3f;

void timeBack(int &h, int &m, int &x){
    if(m - x < 0){
        if(h - 1 < 0)
            h = 23;
        else
            h--;
        m = m + 60 - x;
    }
    else
        m -= x;
}

int isOk(int h, int m){
    if(h % 10 == 7 || h / 10 % 10 == 7 || m % 10 == 7 || m / 10 % 10 == 7)
        return 1;
    return 0;
}

int main()
{
    int x,h,m,ans=0;
    cin >> x >> h >> m;
    while(!isOk(h,m)){
        ans++;
        timeBack(h,m,x);
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

const int INF = 0x3f3f3f3f;
const int MAXN = 2e5+10;

int main()
{
    int x,y;
    int hh,mm;
    scanf("%d", &x);
    scanf("%d%d", &hh, &mm);
    y = 0;
    while(hh%10 != 7 && mm%10 != 7) {
        mm -= x;
        if(mm < 0) {
            hh--;
            if(hh < 0) {
                hh += 24;
            }
            mm += 60;
        }
        y++;
    }
    printf("%d\n",y);
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
void f(int& h, int& m, int n)
{
	m -= n;
	while (m < 0)
	{
		m += 60;
		h -= 1;
	}
	while (h < 0)
		h += 24;
}
int main()
{
	string a, b;
	int x, hour, min, ans = 0;
	cin >> x >> a >> b;
	hour = 10 * (a[0] - '0') + (a[1] - '0');
	min = 10 * (b[0] - '0') + (b[1] - '0');
	for (int cnt[4]; ; )
	{
		cnt[0] = hour / 10, cnt[1] = hour % 10, cnt[2] = min / 10, cnt[3] = min % 10;
		for (int i = 0; i < 4; i++)
		{
			if (cnt[i] == 7)
			{
				cout << ans << endl;
				return 0;
			}
		}
		f(hour, min, x), ans++;
	}
}

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int x,hh,mm;
	cin >> x >> hh >> mm;
	int h1 = hh,h2 = hh,m1 = mm,m2 = mm,count = 0;
	while(1){
		if(m2 % 10 == 7 || h2 % 10 == 7){
			cout << count << endl;
			return 0;
		}
		++count;
		m2 -= x;
		if(m2 < 0){
			m2 += 60;
			h2--;
		}
		if(h2 < 0) h2 += 24;
		//cout << h2 << ":" << m2 << endl;
	}
}

#include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;

int main()
{
	int x;
	int hour;
	int min;
	int num = 0;
	cin >> x;
	cin >> hour >> min;
	while(true)
	{
		if (hour % 10 == 7 || min % 10 == 7)
		{
			break;
		}
		num++;
		min -= x;
		if (min < 0)
		{
			hour -=1;
			min = 60+min;
		}
		if (hour < 0)
		{
			hour = 24+hour;
		}
	}
	cout << num << endl;
}

//Ya Hassan Mojtaba
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll x,h,m,s=0,ans=0,temp=0;
    cin>>x>>h>>m;
    while (1)
    {
        if(m%10==7 || h%10==7)
            break;
        else
        {
            if(x<=m)
                m-=x;
            else
            {
                temp=x,x-=(1+m),m=59,m-=x,x=temp;
                (h>0?h--:h=23);
            }
            ans++;
        }
    }
    return cout<<ans,0;
}

#include <iostream>
using namespace std;
int x;
int h, m;
int cnt;
main() {
	cin>>x;
	cin>>h>>m;
	int h1 = h;
	int m1 = m;
	while ((m1 % 10 != 7 && h1 % 10 != 7) || cnt % x != 0) {
		if (m1 > 0) {
			m1--;
		} else {
			if (h1 > 0) {
				h1--;
				m1 = 59;
			} else {
				h1 = 23;
				m1 = 59;
			}
		}
		//cout<<h1<<" : "<<m1<<endl;
		cnt++;
	}

	cout<<cnt/x<<endl;
}

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
static bool lucky(ii t)
{
	while(t.first>0)
	{
		if(t.first%10==7)
			return true;
		t.first/=10;
	}
	while(t.second>0)
	{
		if(t.second%10==7)
			return true;
		t.second/=10;
	}
	return false;
}
static ii dec(ii t,int x)
{
	if(x==0)
		return t;
	if(t.first+t.second==0)
		return dec(ii(23,59),x-1);
	if(t.second==0)
		return dec(ii(t.first-1,59),x-1);
	return dec(ii(t.first,t.second-min(x,t.second)),x-min(x,t.second));
}
int main() {
	int x;
	cin >> x;
	ii t;
	cin >> t.first >> t.second;
	if(lucky(t))
	{
		cout << 0 << endl;
		return 0;
	}
	for(int y=1;y<1000;y++)
	{
		t=dec(t,x);
		if(lucky(t))
		{
			cout << y << endl;
			break;
		}
	}

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int x,h,m,sum;
inline bool pd(){return (h%10==7||m%10==7);}
int main(){
    cin>>x>>h>>m;
    if(pd()){cout<<0;exit(0);}
    while(1){
		if(h%10==7||m%10==7)break;
		if(m-x<0)m=m+60-x,h=(h+23)%24;
		else m-=x;sum++;
    }
    cout<<sum<<endl;
}

// system.cout(translate *from glut);
#include <bits/stdc++.h>

using namespace std;

#define f for(int i=0;i<n;i++)
const int mod=1e9+7;
vector<long long> p;

int ho,mi,se;
void fix_time()
{   if(se>59)mi+=se/60,se=se%60;if(se<0)se+=60,mi--;
    if(mi>59)ho+=mi/60,mi=mi%60;if(mi<0)mi+=60,ho--;
    if(ho<0)ho+=24;if(ho>24)ho-=24;
}
long long my_pow(int x,int y)
{    long long num=1;
    for(long long i=x;y>0;i=(i*i),y>>=1)
        if(y&1)num=(num*i);
    return num;
}

bool prime[1000001];
void sieve(){
    for(int i=2;i<=1000000;i+=2)
        prime[i]=false,prime[i-1]=true;
    prime[2]=true;
    for(int i=3;i<=1000;i+=2)
        if(prime[i])
            for(int j=i*i;j<=1000000;j+=2*i)
                prime[j]=false;
}
void pfact(long long x)
{   if(x%2==0){p.push_back(2);while(x%2==0)x/=2;}
    for(long long i=3;i*i<=x;i+=2)
        if(x%i==0){p.push_back(i);while(x%i==0)x/=i;}
    if(x>1)p.push_back(x);
}
int n,m,x,y,k,z,l,r,pos,t,gd1,gd2,a[150001],ans;

int main()
{
ios_base::sync_with_stdio(false);
cin>>x>>ho>>mi;
while(1)
{
    if(ho==17||ho==7||mi%10==7)return cout<<ans,0;
    mi-=x;fix_time();ans++;
}

return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

#ifndef ONLINE_JUDGE

#define dbg(x) cout << #x << " = " << x << endl

#else

#define dbg(x)

#endif

using namespace std;

struct myTime
{
	int hh;
	int mm;
	myTime operator-(int x)
	{
		myTime t;
		t.hh = hh;
		t.mm = mm;
		t.mm -= x;
		if (t.mm < 0)
		{
			t.hh--;
			t.mm += 60;
			if (t.hh < 0)
			{
				t.hh += 24;
			}
		}
		return t;
	}
	bool have7()
	{
		if (hh % 10 == 7)
		{
			return true;
		}
		if (mm % 10 == 7)
		{
			return true;
		}
		return false;
	}
};

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);

	int x;
	cin >> x;

	myTime t;
	cin >> t.hh >> t.mm;
	int ans = 0;
	while (!t.have7())
	{
		t = t - x;
		ans++;
	}
	cout << ans << endl;

	cin.get();
	cin.get();
	return 0;
}

// system.cout(translate *from glut);
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int mod=1e9+7;
vector<int> p;

ll n,x,y,sum,cnt1,cnt2,m;
string s1,s2;
ll my_pow(int x,int y)
{    ll num=1;
    for(ll i=x;y>0;i=(i*i)%mod,y>>=1)
        if(y&1)num=((num%mod)*i)%mod;
    return num%mod;
}
void pfact(int x)
{   if(x%2==0){p.push_back(2);while(x%2==0)x/=2;}
    for(int i=3;i*i<=x;i+=2)
        if(x%i==0){p.push_back(i);while(x%i==0)x/=i;}
    if(x>1)p.push_back(x);
}
int dif,i;
int main()
{
   ios_base::sync_with_stdio(false);
   cin>>x;
   cin>>n>>m;

   for( i=m;;i-=x,cnt1++)
    {if(i<0)i+=60,n--;
    if(n<=0)n+=24;if(i%10==7||n%10==7)break;}
    cout<<cnt1;

    return 0;
}

#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
using namespace std;

int main() {
	int x, h, m;
	cin >> x >> h >> m;

	int t = h * 60 + m, res = 0;
	while (t % 60 % 10 != 7 && t / 60 % 10 != 7) {
		res++;
		t -= x;
		t += 24 * 60;
		t %= 24 * 60;
	}

	cout << res;
}

#include<bits/stdc++.h>
using namespace std;
int ld(int n)
{
    if(n%10==7)return 7;
    else return 9;
}
int main()
{
    int x,h,m,i=0;
    scanf("%d%d%d",&x,&h,&m);
    while(1)
    {
        //printf("%d. %d:%d\n",i,h,m);
        if(ld(h)==7||ld(m)==7)
        {
            printf("%d",i);
            break;
        }
        if(m-x<0)m=60-(x-m),h--;
        else m-=x;
        if(h<0)h=23;
        i++;
    }
    return 0;
}

#include<bits/stdc++.h>
#include <algorithm>
#include <utility>
#include <map>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <array>
#include <string.h>
#include <stack>
#include <string>
#include <stdio.h>
#include <queue>
#include <math.h>
#include <iomanip>
#define lli long long int
#define MOD 1000000007
using namespace std;
int main(){
    int x,h,m,count=0; cin>>x>>h>>m;
    while(1){
        if(h==7||h==17||m==7||m==17||m==27||m==37||m==47||m==57){
            cout<<count; return 0;
        }
        else{
            m=m-x;
            if(m<0){
                h-=1;
                if(h<0){
                    h=23;
                }
                m=60+m;
                //cout<<m<<endl;
            }
            if(h==7||h==17||m==7||m==17||m==27||m==37||m==47||m==57){
                count++;
                cout<<count; return 0;
            }
            count++;
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vb vector< bool >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define sort(a) sort(a.begin(),a.end())
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define moddd (1000*1000*1000+9)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define endl "\n"
#define flush fflush(stdout)
#define pi 3.14159265358979323846264338327950
#define primeDEN 727999983
//cout<<fixed<<setprecision(15)<<ans;

template <typename T>
void printvec(vector<T>& vec){
	for(int i=0;i<vec.size();i++){
		cout<<vec[i]<<" ";
	}
	cout<<endl;
}

int hh,mm;
int tot,x;

bool lucky(int a,int b){
	if(b%10==7) return true;
	if(a%10==7) return true;
	return false;
}

int func(int a,int b){
	int tot1=60*a+b;
	int diff=tot-tot1;
	if(tot1>tot) diff=(diff+24*60);
	if(diff%x!=0) return INT_MAX;
	return diff/x;
}

int main(){
	std::ios::sync_with_stdio(false);
	int ttt=1;
	//cin>>ttt;
	while(ttt--){
		int i;
		cin>>x>>hh>>mm;
		tot=60*hh+mm;
		int a,b;
		int ans=INT_MAX;
		for(a=0;a<=23;a++){
			for(b=0;b<=59;b++){
				if(!lucky(a,b)) continue;
				ans=min(ans,func(a,b));
			}
		}
		cout<<ans;
	}
	return 0;
}

// IN THE NAME OF GOD
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int s, h, m;
bool chk(int a, int b){
  if(a % 10 == 7 || b % 10 == 7) return true;
  return false;
}
int solve(int mm, int snooze, int cnt){
  if(chk(mm / 60, mm % 60)) return cnt;
  if(mm < snooze) return solve(1440 - (snooze - mm), snooze, cnt + 1);
  return solve(mm - snooze, snooze, cnt + 1);
}
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> h >> m;
  cout << solve(m + h * 60, s, 0);
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll x; cin>>x;
    ll hrs, min; cin>>hrs>>min;
    bool cond = false;
    int count = 0;
    while(cond == false){
        ll h = hrs, m = min;
        //cout<<h<<" "<<m<<endl;
        while(h>0){
            int first = h%10;
            h /= 10;
            if(first == 7)
            cond = true;
        }
        while(m>0){
            int first = m%10;
            m /= 10;
            if(first == 7)
            cond = true;
        }
        if(cond == true)
            break;
        min -= x;
        if(min < 0){
            hrs -= 1;
            if(hrs<0)
            hrs = 24+hrs;
            min = min+60;
        }
        count++;
    }
    if(cond == true){
        cout<<count<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int x;
	cin>>x;
	int h,m;
	cin>>h>>m;
	int cnt = 0;
	while(1)
	{
		if(m%10==7||m/10==7||h%10==7||h/10==7)
		{
			cout<<cnt<<endl;
			break;
		}
		m -= x;
		if(m<0)
		{
			m += 60;
			h--;
			if(h==24)
			{
				h = 0;
			}
			else if(h<0)
			{
				h += 24;
			}
		}
		cnt++;
	}
	return 0;
 }

#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<bitset>

using namespace std;

inline int read()
{
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
        {
            w=-1;
        }
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*w;
}
inline void print(int x)
{
    if(x<0)
    {
        x=-x;
        putchar('-');
    }
    if(x>=10)
    {
        print(x/10);
    }
    putchar(x%10+'0');
}
int x,h,m;
int ans;
int main()
{
    x=read();
    h=read();
    m=read();
    if(h%10==7||m%10==7)
    {
        print(0);
        return 0;
    }
    else
    {
        while(1)
        {
            if(h%10==7||m%10==7)
            {
                print(ans);
                break;
            }
            else
            {
                if(m>x)m-=x,ans++;
                else
                {
                    if(m==x)m=0,ans++;
                    else
                    {
                        m=60-x+m;
                        h=(h+23)%24;
                        ans++;
                    }
                }
            }
        }
    }
}

#include<bits/stdc++.h>
using namespace std;

#define LL long long
int k, x, y, ans = 1e9;

bool ok(int x) {return (x % 10 == 7);}

int f(int x, int y, int a, int b) {
    if(a > x || (a == x && b > y)) {
        int res = (24 * 60) - ((a - x) * 60 + b - y);
        if(res % k == 0) return res / k;
        else return 1e9;
    }
    else {
        int res = (x - a) * 60 - b + y;
        if(res % k == 0) return res / k;
        else return 1e9;
    }
    return 1e9;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> k >> x >> y;
    for(int i = 0; i <= 23; i++) {
        for(int j = 0; j <= 59; j++) {
            if(ok(i) || ok(j)) {
                ans = min(ans, f(x, y, i, j));
            }
        }
    }
    cout << ans;
}

#include<iostream>
using namespace std;
int main (){
	int x,h,m,pas=0;
	cin>>x>>h>>m;
	while(h%10!=7 && m%10!=7){
		m-=x;
		if(m<0){
			m+=60;
			h--;
		}
		if(h<0)h=23;
		pas++;
	}
	cout<<pas;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,hh,mm;
    cin>>x;
    cin>>hh>>mm;
    int a,b,remh=0,remm=0,cnt=0;
    a=hh;
    b=mm;
    while(a>0)
    {
        remh=a%10;
        if(remh==7)
            break;
        a=a/10;
    }
    while(b>0)
    {
        remm=b%10;
        if(remm==7)
            break;
        b=b/10;
    }
    if(remh==7||remm==7)
        cout<<"0"<<endl;
    else
    {
        while(mm!=7&&mm!=17&&mm!=27&&mm!=37&&mm!=47&&mm!=57&&hh!=7&&hh!=17)
        {
            mm=mm-x;
            if(mm<0)
            {
                mm=mm+60;
                hh=hh-1;
                if(hh<0)
                    hh=hh+24;
            }
            ++cnt;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int x,h,m;
LL cnt;
int main()
{
	scanf("%d",&x);
	scanf("%d %d",&h,&m);
	cnt = 0;
	for(;;)
	{
		if(m%10==7||h%10==7)
		{
			printf("%d\n",cnt);
			return 0;
		}
		m-=x;
		if(m<0)
		{
			m=60+m;
			h--;
			if(h<0)
				h=23;
		}
		cnt++;
	}
	return 0;
}

#include <iostream>
using namespace std;
int main ()
{
    int x,hh,mm;
    while (cin >> x>>hh>>mm)
    {
        if (hh/10==7||hh%10==7||mm/10==7||mm%10==7)
        {
            cout << "0"<<endl;
            continue;
        }
        else
        {
                int t=0;
                while (mm%10!=7&&mm/10!=7&&hh/10!=7&&hh%10!=7)
                {
                    t++;
                    mm=mm-x;
                    if (mm<0&&hh>0)
                    {
                              mm=mm+60;
                              hh--;
                    }
                    else if (mm<0)
                    {
                                   mm=mm+60;
                                   hh=23;
                    }
                }
                cout << t<<endl;
                continue;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int x;
    cin>>x;
    int h,m;
    cin>>h>>m;
	int y=0;
	while(h%10!=7 && m%10!=7)
	{
		m=m-x; y++;
		if(m<0)
		{
		m=60+m;
		h--;
		if(h<0)
		h=23;
	    }
	}
	cout<<y;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

#pragma warning(disable:4996)

using namespace std;

int x, H, M, ans;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	scanf("%d%d%d", &x, &H, &M);
	if (H % 10 == 7 || M % 10 == 7)
	{
		printf("0");
		return 0;
	}
	ans = 0;
	while(H % 10 != 7 && M % 10 != 7)
	{
		M -= x;
		if (M < 0)
		{
			H--;
			M = 60 + M;
			if (H < 0)
			{
				H = 24 + H;
			}
		}
		ans++;
	}
	printf("%d", ans);
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define F(i,n) for(i=0;i<n;i++)
#define vi vector<int>
#define vvi vector< vector<int> >
#define pb push_back
#define all(c) c.begin(), c.end()
#define pii pair<int, int>
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define MOD 1000000007
using namespace std;
int main(int argc, char* argv[])
{
	ll x, h, m;
	cin >> x;
	cin >> h >> m;
	ll step=0;
	if(h%10==7 || m%10==7)
	{
		cout << 0 << endl;
	}
	else if(h<7)
	{
		m+=60*(h+6);
		while(m>=0 && m%10!=7)
		{
			m-=x;
			step++;
		}
		cout << step << endl;
	}
	else if(h>17)
	{
		m+=60*(h-18);
		while(m>=0 && m%10!=7)
		{
			m-=x;
			step++;
		}
		cout << step << endl;
	}
	else
	{
		m+=60*(h-8);
		while(m>=0 && m%10!=7)
		{
			m-=x;
			step++;
		}
		cout << step << endl;
	}
	return 0;
}

#include <iostream>
using namespace std;
int x,h,m,t;
int main() {
	cin >> x >> h >> m;
	for(;;) {
		if(h%10==7||m%10==7) {
			cout<<t;
			return 0;
		}
		m-=x;
		if(m<0) {
			h--;
			m+=60;
		}
		if(h<0) h+=24;
		t++;
	}
}

#include<bits/stdc++.h>

using namespace std;

bool has(int p){
	if((p % 10 == 7) || (p / 10 == 7)) return true;
	return false;
}

int main(){
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	int ans = 0;
	while(!(has(x) || has(y))){
		y -= n;
		if(y < 0){
			y += 60;
			x--;
			if(x < 0) x += 24;
		}
		ans++;
	}

	printf("%d\n", ans);

	return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int x,y=0,hh,mm;
	string s;
	cin>>x>>hh>>mm;
	while(1)
	{
		s=to_string(hh)+""+to_string(mm);
		//cout<<s<<endl;
		if(s[0]=='7' || s[1]=='7' || s[2]=='7' || s[3]=='7') break;
		mm-=x;
		if(mm<0)
		{
			hh=hh-1<0?23:hh-1;
			mm=60+mm;
		}
		y++;
	}
	cout<<y<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fo(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfo(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define mod1 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define inf LLONG_MAX
#define endl "\n"
#define f first
#define s second
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
#define sz(c) (int)c.size()
#define debug1(x)            cout<<#x<<"="<<x<<endl;
#define debug2(x,y)          cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define debug3(x,y,z)        cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define debug4(x,y,z,w)      cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<" "<<#w <<"="<<w<<endl;
#define debugarray(arr,j,n)  for(int i=j;i<n;i++) {cout<<"i="<<i<<" arr[i]="<<arr[i]<<"\n";}
//MODULAR OPERATIONS
#define mod 1000000007
ll add(ll a,ll b){
    ll ans = a+b;
    ans-= ans>=mod ? mod : 0;
    return ans;
}
ll sub(ll a, ll b){
    return (a-b+mod)%mod;
}
ll mul(ll a,ll b){
    return (a*b)%mod;
}
ll pow(ll a, ll b){
    ll ans = 1;
    while(b>0)
        if(b&1) ans = mul(ans,a),b--;
        else a = mul(a,a),b >>= 1;
    return ans;
}
ll nCr(ll n,ll r){
    if(r==0)return 1;
    if(r==1)return n;
    if(n==0)return 0;
    return mul(n,mul(nCr(n-1,r-1),pow(r,mod-2)));
}

/* use:-

///////////////////
goto done;
done:
code continues
///////////////////

// insted of using multiple swap
*/
///////////////////////////////////
const int Nmax = 1000005;

////////////////////////////////////

void solve(){

  int n;
  cin >> n;

  int count = 0;

  int h, m;
  cin >> h >> m;

  while(true){

    if(h%10 == 7 || m%10 == 7){
        break;
    }
    if(m - n > 0){

        count++;
        m-=n;
        /*debug1(m);*/
    }

    else if(m-n == 0){
        count++;
        m-=n;

    }

    else{

        count++;
        m = m - n + 60;

        h = (h-1 + 24)%24;

    }

  }

    cout << count << endl;

    }

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
        ios_base::sync_with_stdio(false); cin.tie(0);

        int t = 1;
       // cin >> t;

        while(t--){

            solve();
        }

  }

#include<stdio.h>
int increase(int hh,int mm,int x)
{
    int i,j,k,stroke=0;
    while((hh%10)!=7&&(mm%10)!=7&&(hh/10)!=7&&(mm)/10!=7)
    {
        mm-=x;
        if(mm<0)
        {
            //printf("mm");
            mm+=60;
            hh--;
            if(hh<0)
                hh+=24;
        }
        stroke++;
    }
    return stroke;
}
int main()
{
    int x,hh,mm,i,j,k;
    scanf("%d",&x);
    scanf("%d %d",&hh,&mm);
    printf("%d\n",increase(hh,mm,x));
}

#include <bits/stdc++.h>
using namespace std;

int x, h, m, num = 0;

vector<int> primes;

void seive()
{
	bool vis[1000004] = { false };

	for (int i = 2; i*i <= 1e6; i++)
	{
		if (vis[i])continue;
		for (int j = 2 * i; j <= 1e6; j += i)
			vis[j] = true;
	}
	for (int i = 2; i <= 1e6; i++)if (!vis[i])primes.push_back(i);
}

int main()
{
	ios_base::sync_with_stdio(false);

	//seive();

	//cout << primes.size();

	cin >> x >> h >> m;

	int res = h * 60 + m;

	while (true)
	{
		if ((res / 60) % 10 == 7 || (res % 60) % 10 == 7)return cout << num, 0;
		if (res - x >= 0)
			res -= x;
		else
			res = 1440 + (res - x);
		num++;
	}
	return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>

#define INF 1000000000
#define FOR(i, n) for (int i = 0; i < n; i++)
#define For(i, x, n) for (int i = x; i < n; i++)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define in insert
#define ft first
#define sd second
#define sz size()
#define emp empty()
#define end end()
#define bn begin()
#define of ifstream cin ("input.txt");ofstream cout ("output.txt");
#define pii pair<int, int>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

using namespace std;

    ll x, y;
    int q;

    bool check (int a) {
        return ((a/60)%10 == 7 || a % 10 == 7) && !(((1440+x-a)%1440) % q);
    }

int main()
{

    cin >> q;
    cin >> x >> y;
    x = x*60 + y;
    ll mn = INF;
    FOR(i, 1440) {
        if (check(i)) {
            mn = min(mn, (1440+x-i)%1440);
        }
    }

    cout << (mn+q-1)/q;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int n;
int hh,mm;
int ans = 0;
bool isit(int x,int y)
{
	if(x%10==7)return 1;
	if(y%10==7)return 1;
	return 0;
}
int main()
{
	scanf("%d",&n);
	scanf("%d%d",&hh,&mm);
	while(isit(hh,mm)==0){
		if(mm-n<0){
			mm = mm+60;
			hh--;
			if(hh<0){
				hh = 23;
			}
		}
		mm = mm-n;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<iomanip>
#include<cmath>
#include<functional>
using namespace std;

#define ll long long
#define INF 0x3f3f3f3f
#define eps 1e-6
#define MAX 1000 + 5
#define e exp(1)

int main() {
	int x;
	cin >> x;
	int hh, mm;
	cin >> hh >> mm;
	int ans = 0;
	while (1) {
		if (hh % 10 == 7 || mm % 10 == 7) {
			cout << ans << endl;
			break;
		}
		ans++;
		mm -= x;
		if (mm < 0) {
			mm += 60;
			hh = (hh - 1 + 24) % 24;
		}
	}
	//system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define next Next
int x,a,b,gs;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	x=read();
	a=read();b=read();
	if(a/10==7||a%10==7||b%10==7||b/10==7)
	{
		cout<<gs;
		return 0;
	}
	while(true)
	{
		b-=x;
		if(b<0)
		{
			b+=60;
			a--;
			if(a<0)a=23;
		}
		gs++;
		if(a/10==7||a%10==7||b%10==7||b/10==7)
		{
			cout<<gs;
			return 0;
		}
	}
}

#include<iostream>
using namespace std;
int main()
{
    int x,hh,mm,ans=0;
    cin>>x>>hh>>mm;
    while(1)
    {
        if(hh%10==7||mm%10==7)
        {
            cout<<ans;
            break;
        }
        ans++;
        mm-=x;
        while(mm<0)
        {
            mm+=60;
            hh--;
        }
        while(hh<0)
            hh+=24;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
    int x, h, m;
    cin >> x >> h >> m;
    int answer = 0;
    while (h%10 != 7 && m%10 != 7)
    {
        m -= x;
        if (m < 0)
        {
            h--;
            if (h < 0)
                h = 23;
            m += 60;
        }
        answer++;
    }
    cout << answer;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,res=0;
    int h,m;
    cin>>x;
    cin>>h>>m;
    while(1)
    {
        if(m%10!=7&&h%10!=7)
        {
            if(m==0)
            {
                m=59;
                if(h==0)
                    h=23;
                else
                    h--;
            }
            else
                m--;
            res++;
            //cout<<h<<" "<<m<<endl;
        }
        else
        {
            if(res%x==0)
            {
                cout<<res/x;
                return 0;
            }
            m--;
            res++;
        }
    }
}

// Jamie and Alarm Snooze.cpp : Defines the entry point for the console application.
//

#include <stdio.h>

int X, H, M;

void scan()
{
	scanf("%d", &X);
	scanf("%d", &H);
	scanf("%d", &M);
}

void calc()
{
	int t = H * 60 + M;

	for (int i = 0;; ++i)
	{
		int h = t / 60, m = t % 60;
		if (h % 10 == 7 || h / 10 == 7 || m % 10 == 7 || m / 10 == 7)
		{
			printf("%d", i);
			return;
		}
		t = (t - X + 24 * 60) % (24 * 60);
	}
}

int main()
{
	scan();

	calc();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int x;
    cin >> x;
    int hh, mm;
    cin >> hh >> mm;
    int n_snooze = 0;
    while(true) {
        if(hh % 10 == 7 || mm % 10 == 7) {
            cout << n_snooze;
            exit(0);
        }
        mm -= x;
        n_snooze++;
        if(mm < 0) {
            mm = 60 + mm;
            hh--;
        }
        if(hh < 0) {
            hh = 24+hh;
        }
    }
}

#include <iostream>

int main()
{
	int x, hh, mm;
	std::cin >> x >> hh >> mm;
	int now = hh * 60 + mm;
	int y = 0;
	while (true) {
		int p = (now - x * y + 1440) % 1440;
		int h = p / 60;
		int m = p % 60;
		if (h % 10 == 7 || h / 10 == 7 || m % 10 == 7 || m / 10 == 7) break;
		y++;
	}
	std::cout << y << '\n';
    return 0;
}

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdio.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <cmath>
#include <cstdio>
#include <iomanip>

#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, n) for (int i = 1; i <= n; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation

const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 111;

using namespace std;

int main()
{
	int x, a, b, k = 0, ans = 0, d, f;

	cin >> x >> a >> b;

	d = a;
	f = b;
	while (true)
	{
		if (a % 10 == 7 || a / 10 % 10 == 7 || b % 10 == 7 || b / 10 % 10 == 7)
			break;
		b += x;
		if (b >= 60)
        {
        	b %= 60;
        	a++;
        	a %= 24;
        }
	}
	while (true)
	{
		if (a == d && b == f)
			break;
		b += x;
		ans++;
		if (b >= 60)
        {
        	b %= 60;
        	a++;
        	a %= 24;
        }
	}
	while (true)
	{
		if (a % 10 == 7 || a / 10 % 10 == 7 || b % 10 == 7 || b / 10 % 10 == 7)
		{
			ans = min(k, ans);
			break;
		}
		b -= x;
		k++;
		if (b < 0)
        {
        	b = 60 + b;
        	a--;
        	if (a < 0)
        		a = 24 + a;
        }
	}

	cout << ans;

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;

int main() {
	int x;
	cin >> x;
	int hh, mm;
	cin >> hh >> mm;

	int cnt = 0;
	string str_hh = to_string(hh);
	string str_mm = to_string(mm);

	bool isSeven = false;
	for (int i = 0; i < str_hh.size(); i++) {
		if (str_hh.at(i) == '7') {
			isSeven = true;
			break;
		}
	}
	for (int i = 0; i < str_mm.size(); i++) {
		if (str_mm.at(i) == '7') {
			isSeven = true;
			break;
		}
	}
	if (isSeven) {
		cout << cnt;
	}
	else {
		while (true) {
			cnt++;
			int min = ((mm - x) + 60) / 60;
			mm = ((mm - x)+60) % 60;
			hh = (hh + (min -1) + 24) % 24;

			string str_hh = to_string(hh);
			string str_mm = to_string(mm);

			for (int j = 0; j < str_hh.size(); j++) {
				if (str_hh.at(j) == '7') {
					isSeven = true;
					break;
				}
			}
			for (int j = 0; j < str_mm.size();j++) {
				if (str_mm.at(j) == '7') {
					isSeven = true;
					break;
				}
			}
			if (isSeven) {
				break;
			}
		}
		cout << cnt;
	}

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k,z=0,x,y=0;
    string s,d;
    cin>>a>>b>>c;
    for(j=c;;j=j-a)
    {
        if(j<0)
        {
            j=j+60;
            b--;
            if(b<0)
            {
                b=b+24;
            }
        }
        k=b;
        while(k!=0)
        {
            x=(k%10);
            if(x==7)
            {
                z=1;
                break;
            }
            k=k/10;
        }
        k=j;
        while(k!=0)
        {
            x=(k%10);
            if(x==7)
            {
                z=1;
                break;
            }
            k=k/10;
        }
        if(z==1)
        {
            break;
        }
        y++;
    }
    cout<<y<<endl;
}

#include <iostream>
using namespace std;
int main() {
    int c,j,n,h,m,i=0;
    cin>>c>>h>>m;
    j=h*60+m;
    while ((j%10!=7)&&(j/60%10!=7)){
        if (j-c>0) {
        j-=c;}else{
            j=1440-(c-j);
        }
        i+=1;
    }
    cout<<i;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define LL  long long
#define pb push_back
#define maxv(c) max_element(c.begin() , c.end())
#define minv(c) min_element(c.begin() , c.end())
#define sort(c) sort(c.begin() , c.end())
#define rm(c , item) c.erase(remove(c.begin() , c.end() ,item) , c.end())
#define revv(c) reverse(c.begin() , c.end())
#define unique(c) c.erase(unique(c.begin() , c.end()) , c.end())
#define existv(c, item) if ( find(c.begin() ,c.end() , item) != c.end() ) // use sort before
#define Q cout << "\n"
string int_to_string( int item)
	{

		stringstream ss;
		ss << item;
		return ss.str();

	}

int string_to_int( string item)
	{
		stringstream ss(item);
		int x=0;
		ss >> x;
		return  x;
	}

	int main()
		{
				string h_m;
				string s_m;
				string hh , mm;
			int i, j=0;
			int x;

			bool f1=1;
			bool f2=1;

			cin >> x >> hh >> mm ;

			for ( i=0; i< hh.length() ; i++ )
					{

						if ( hh[i] ==  '7')
						{
							f1 =0;
						}
					}

			for ( i=0; i < mm.length() ; i++)
					{
						if (mm[i] == '7')
						{
							f2=0;
						}
					}

			if (  f1 == 0 or  f2 ==0 )
				{
					cout << 0 ; return 0;
				}

			int h_int = string_to_int(hh);
			int m_int = string_to_int(mm);

			// main  part
			bool p1=1;
			bool p2=1;

			for ( i = 1 ; ;i++ )
			{
				m_int = m_int - x;

				if (m_int <0 )
				{
					h_int--;
					m_int = 60 - (fabs(m_int));
				}

				//cout << h_int << " --> " << m_int;Q;
				if (m_int >= 60)
				{
					h_int++;
					m_int = 60 -m_int;
				}

				if ( h_int == 24)
				{
					h_int =0;;
				}

				 s_m = int_to_string(m_int);
				 h_m = int_to_string(h_int);

				for  ( j=0; j< s_m.length() ; j++)
				{
					if (s_m[j] == '7')
					{
						p1 =0;
					}
				}

				for ( j=0; j < h_m.length() ; j++)
				{
					if ( h_m[j] == '7')
					{
						p2=0;
					}
				}

				if ( p1 * p2 ==0 )
				{
					break;
				}

			//cout << h_m << " : " << s_m ;Q;;

			}

			//cout << h_m << " : " << s_m ;Q;;
			cout << i ; Q;

		}

#include<iostream>
#define ll long long
using namespace std;

bool check(ll h,ll m)
{
    if(h%10==7 || m%10==7)
    {
        return true;
    }

    return false;
}

int main()
{
    ll x;
    cin>>x;
    ll h,m;
    cin>>h>>m;
    bool ans=check(h,m);
    if(ans)
    {
        cout<<"0";
        return 0;
    }

    ll steps=0;
    while(!check(h,m))
    {
        m=m-x;
        if(m<0)
        {
            m+=60;
            h--;
            if(h<0)
            {
                h=23;
            }
        }

        steps++;
    }

    cout<<steps;
    return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main() {
    int x, a, b, aa, bb;
    scanf("%d", &x);
    scanf("%d%d", &a, &b); aa = a, bb = b;
    for(int i = 0; i <= 24*60; i ++) {
        int tmp = x*i; a = aa, b = bb;
        while(b < tmp) { b += 60; a --; if(a == -1) a = 23; }
        b -= tmp;
        if(b%10 == 7 || b/10 == 7 || a%10 == 7 || a/10 == 7) {
            printf("%d\n", i);
            return 0;
        }
    }
}

#include<bits/stdc++.h>

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              1234567899
#define PI              2*acos(0.0)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for(__typeof(i) i=a; i<=b; i++)
#define rev(i,a,b)      for(__typeof(i) i=a; i>=b; i--)

using namespace std;

bool check(int h,int m)
{
    if(m%10==7 || (m/10)%10==7 || h%10==7 ||(h/10)%10==7) return 1;
    else return 0;
}
int main()
{
    int x,h,m,cnt=0;
    cin>>x;
    cin>>h>>m;
    while(1)
    {
        //cout<<h<<' '<<m<<endl;
        if(check(h,m))
        {
            cout<<cnt<<endl;
            break;
        }
        if(m>=x)m-=x;
        else{
            m=(m+60)-x;
            if(h!=0)h--;
            else h=23;
        }
        cnt++;
    }
}

#include<iostream>
using namespace std;
int main()
{
	int t,n,hh,mm,a,y=0,b,c,d,sum=0;
	cin>>n>>hh>>mm;
	a=hh/10;
	b=hh%10;
	c=mm/10;
	d=mm%10;
	if(b==7 || d==7){
		cout<<0<<endl;
	}
	else
	{
		while(y!=1 || sum%n!=0){
				y=0;
			if(mm!=0) mm--;
			else {
					mm=59;
				if(hh!=0) hh--;
			    else hh=23;
			}
			a=hh/10;
	b=hh%10;
	c=mm/10;
	d=mm%10;
			if(b==7 || d==7) y=1;
			sum++;
		}
		cout<<sum/n<<endl;
	}
}

#include <iostream>

/*
http://codeforces.com/contest/916/problem/A
*/
using namespace std;

bool C7(int num){
	if(num%10==7)
	return true;

	else
	return false;
}//contains 7

int main(){

	int hh, mm, t;
	while(cin >> t){
		cin >> hh >> mm;
		if(C7(hh) || C7(mm)){
			cout << 0 << endl;
		}else{
			int index=0;
			while( !(C7(hh) || C7(mm)) ){
				if(mm<t){
					if(hh==0)
					hh=24;

					hh--;
					mm += 60;
				}
				mm -= t;
				index++;
			}
			cout << index << endl;
		}
	}

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int increment, m, h, count = 0;

    cin >> increment;
    cin >> h >> m;

    for(int i = h; i > (h-24); i--)
    {
        while(m >= 0)
        {
          //cout << i << " : " << m << " " << count << endl;
          if(i == 7 || i == 17 || i == -7 || i == -17 || m == 7 || m == 17 || m == 27 || m == 37 || m == 47 || m == 57)
          {
              if(m == 60)
                cout << count + 1;
              else
                cout << count; //cout << i << " : " << m << " " << count;
              return 0;
          }

            count++;
            m -= increment;
        }

        m += 60;
    }

	return 0;

}

#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int x, hh, mm ,i;

	i = 0;
	cin >> x;
	cin >> hh;
	cin >> mm;

	while (mm % 10 != 7 && hh % 10 != 7)
	{
		mm = mm - x;

		if (mm < 0)
		{
			mm = mm + 60;

			if (hh == 0)
				hh = 23;

			else hh--;
		}

		i++;
	}

	cout << i;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,h,m,k=0;
    cin>>x>>h>>m;
    while(1){
        if(h%10==7||m%10==7)
            break;
        m=m-x;
        if(m<0){
            m=60+m;
            h--;
            if(h<0)
               h=23;
        }
        k++;
    }
    cout<<k<<endl;
}

#include <iostream>
using namespace std;
int main(){
int x,hh,mm;
cin>>x;
cin>>hh>>mm;
int i,j,k=0;
while(1){
  if(hh%10==7||mm%10==7)
{
cout<<k;
return 0;
}
else{
	mm=mm-x;
	k=k+1;
	if(mm<0){
		mm=60+mm;
        hh=hh-1;
        if(hh<0){
        	hh=hh+24;
        }
	}
}

}

return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

class Solution{
public:

    int x,h,m;
    int minutes;
    int hours;
    Solution(){
        cin >> x >> h >>m ;

    }

    pair<int, int> findClosestWith7();
    int getAnswer();
};

pair<int, int> Solution::findClosestWith7() {

    int h =this->h;
    int m = this->m;
    minutes = 0;

    while(true){
        if(h % 10 == 7 || h/10 == 7 || m % 10== 7 || m/10 == 7){
            break;
        }
        m--;
        minutes ++;
        if(m < 0){
            m=59;

            if(h<0){
                h=23;
            }
        }

    }

    return {h,m};
}

int Solution::getAnswer() {
    auto timeWith7 = findClosestWith7();
    return minutes/x;
}

int main() {

    Solution solution;
    cout << solution.getAnswer() << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int x ;
    cin >> x ;
    int h , m ;
    cin >> h >> m ;
    if(h==0)
        h=24;
    int counter = 0 ;
    int a = h , b = m ;
    while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
    while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
    while(h){
        bool ans = false ;
        if(m>=x){
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
        else {
            if(h>1)
                h--;
            else
                h = 12 ;
            m=60+m;
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k;
	cin >> k >> n >> m;
	int s = 0;
	for(int i = 0;;i ++){
		if(n % 10 == 7 || m % 10 == 7){
			break;
		}
		if(m - k >= 0){
			m -= k;
			s ++;
		} else if (n - 1 >= 0){
			n --;
			m += 60 - k;
			s ++;
		} else if (n - 1 < 0){
			n = 23;
		}
	}
	cout << s;
}

#include<iostream>
using namespace std;
int hh,mm,x;
bool lucky(){
	if((mm % 10==7)||(mm / 10==7)||(hh % 10==7)||(hh / 10==7))
	return true;
	else
	return false;
}
int main(){
	//int x,hh,mm;
	cin>>x;
	cin>>hh>>mm;
	int counter=0;
	while(!lucky()){
		if(mm==0){
			if(hh>0)
			hh--;
			else
			hh=23;
			mm=60-x;
			counter++;
		}
		else
		if(x<=mm){
			mm-=x;
			counter++;
		}
		else
		if(x>mm){
			if(hh>0)
			hh--;
			else
			hh=23;
			mm=60-(x-mm);
			counter++;
		}
	}
	cout<<hh<<" "<<mm<<endl;
	cout<<counter;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

typedef long long ll;
using namespace std;

int main()
{
    int x;
    int hh,mm;
    scanf("%d",&x);
    scanf("%2d%2d",&hh,&mm);
    int a=hh%10,b=mm%10;
    int y=0;
    while(1)
    {
        a=hh%10;b=mm%10;
        if(a==7||b==7)
        {
            printf("%d\n",y);
            return 0;
        }
        int t=mm-x;
        mm=t%60;
        if(t<0)
            hh--;
        hh=hh%24;
        y++;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main(){
	int count=0,a,k,l,m,n;
	cin>>a;
	int h;
	cin>>h>>m;
	while(h%10!=7&&m%10!=7){
		if(m>a) m=m-a;
		else {
			m=(m+60-a);
			h--;
		}
		if(h==0) h=24;
		count++;
	}
	cout<<count;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int increment, m, h, count = 0;

    cin >> increment;
    cin >> h >> m;

    for(int i = h; i > (h-24); i--)
    {
        for(int j = m; j >= 0; j -= increment)
        {

          if(i == abs(7) || i == abs(17) || j == 7 || j == 17 || j == 27 || j == 37 || j == 47 || j == 57)
          {
              cout << count;
              return 0;
          }

          count++;
        }

        m += 59;
    }

    cout << "nothing happened";
	return 0;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ff first
#define ss second
#define pb push_back
string toString(ll x) {  stringstream ss; ss<<x; string s=ss.str(); return s; }
ll toInteger(string s){ stringstream ss(s); ll x=0; ss>>x; return x;}

bool chk(ll x)
{
    ll tm=x;
    while(tm)
    {
        ll p=tm%10;
        tm/=10;
        if(p==7)
            return true;
    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll k,h,m;
    cin>>k>>h>>m;
    ll x=m+h*60;
    if(chk(h) || chk(m))
    {
        cout<<"0\n";
        return 0;
    }
    while(1)
    {
        if(m==0)
        {
            h--;
            m=59;
            if(h<0)
               h=23;
        }
        else
            m--;
        if(chk(h) || chk(m))
            break;
    }
    ll y=m+h*60;
    ll d=x-y;
    if(d<0)
        d+=1440;
    ll ans=d/k;
    if(d%k)
        ans++;
    cout<<max(1LL,ans)<<endl;
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
int n,m,t,hh,mm;
int main(){
	int i,j;
	scanf("%d",&n);
	scanf("%d%d",&hh,&mm);
	int ans=inf;
	int temp=hh*60+mm;
	int h=hh,m=mm,flag=0;
	while(1){
		if(flag==0){
			if((h%10==7&&h!=0)||(m%10==7&&m!=0)){
				int tem=h*60+m;
				int k=abs(temp-tem);
				ans=k/n;
				if(k%n!=0)
					ans++;
				break;
			}
		}
		else{
			if((h%10==7&&h!=0)||(m%10==7&&m!=0)){
				int tem=24*60-h*60-m;
				int k=abs(temp+tem);
				ans=k/n;
				if(k%n!=0)
					ans++;
				break;
			}
		}
		m--;
		if(h==0&&m<=0){
			h=23,m=59;
			flag=1;
		}

	}
	printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int ChkSVN(int n)
{
    int F=0;
    while(n>0){
    if(n % 10==7){F=1;break;}
    else F=0;
    n/=10;
    }
    if(F==1)return 1;
    else return 0;
}
int ChkHR(int h,int m,int x)
{
    int c=0,t=0,r=0,hh=0;
    t=(h*60)+m;
    while(hh!=1)
    {
        t-=x;
        r=t/60;
        hh=ChkSVN(r);
        c++;
    }
    return c;
}
int ChkMN(int h,int m,int x)
{
    int mm=0,c=0;
    while(mm!=1)
    {
        m-=x;
        mm=ChkSVN(m);
        c++;
        if(m<0) {m+=x*c;c=0;break;}
    }
    if(c==0)return ChkHR(h,m,x);
    else return c;
}

int main()
{
    int x,h,m,c=0;
    cin>>x>>h>>m;
    if(ChkSVN(h) || ChkSVN(m)) cout<<"0";
    else
    {
        if(m>x )
        {
            cout<<ChkMN(h,m,x);
        }
        else if(m<x)
        {
            cout<<ChkHR(h,m,x);
        }
    }

}

// C++ program to insert element in binary tree
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
bool CheckLucky(int x,int y){
    int a=x%10;
    int b=x%10;
    if (b==7||a==7)
        return true;
    return false;
}
int main()
{
    int x=0,k=0;
    cin>>x;
    int a=0,b=0;
    cin>>a>>b;
    while (!CheckLucky(a,b)){
        b=b-x;
        k++;
        if (b==0){
            b=59;
            a--;
        }
        if (b<0){
            int t=abs(b);
            b=59-t;
            a--;
        }
    }
    cout<<k;
}

#include<bits/stdc++.h>

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              123456789
#define PI              2*acos(0.0)
#define rep(i,a,b)      for(__typeof(i) i=a; i<=b; i++)
#define rev(i,a,b)      for(__typeof(i) i=a; i>=b; i--)

using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    CIN;
    int arr[] = {7,17,27,37,47,57,7};
    ll n, pos = 5, a1, b1, a2 = 0, b2, ans = 0, x, y;
    cin>>n>>a1>>b1;
    b2 = a1;
    x = b1;
    bool fl = 1;
    for(int i=x; fl ;i--)
    {
        for(int j = i; fl && j ; j/=10)
        {
            if((j%10)==7||(a1%10)==7)
            {
                y = i;
                fl = 0;
            }
        }
        if(i==0) {i = 60;a1--;}
    }
    //cout<<a1<<' '<<y<<' '<<ans<<endl;
    ans = abs((b2*60+b1)-(a1*60+y));
    for(int i=ans;i>0;i--)
    {
        if(i%n==0)
        {
            a2 = i/n;
            break;
        }
    }
    cout<<a2<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair< int,int > ii;
typedef pair< int,ii > iii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 100005;
const int MOD = 1e9+7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

bool ok( int val ) {
    while( val ) {
        int r = val%10;
        if( r == 7 ) return true;
        val /= 10;
    }
    return false;
}
int main( int argc, char const *argv[] ) {
    int x , h , m;
    cin >> x >> h >> m;
    if( ok(h) || ok(m) ) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    while( true ) {
        m --;
        ans ++;
        if( m <= 0 ) m = 59 , h--;
        if( h <= 0 ) h = 23;
        if( ok(h) || ok(m) ) break;
    }
    cout << 1+(ans-1)/x << endl;
    return 0;
}

#include<bits/stdc++.h>
#include <algorithm>
#include <utility>
#include <map>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <array>
#include <string.h>
#include <stack>
#include <string>
#include <stdio.h>
#include <queue>
#include <math.h>
#include <iomanip>
#define lli long long int
#define MOD 1000000007
using namespace std;
int main(){
    int x,h,m; cin>>x>>h>>m;
    int h1=h,m1=m;
        while(h1){
            if(h1%10==7){
                cout<<0;
                return 0;
            }
            h1/=10;
        }
        while(m1){
            if(m1%10==7){
                cout<<0;
                return 0;
            }
            m1/=10;
        }
        if(m%10==8){
            cout<<1; return 0;
        }
        if(m%10==9){
            if(x==1){
                cout<<2;
            }
            else{
                cout<<1;
            }
            return 0;
        }
        if(h==8||h==18&&m>=0||m<7){
            int ans=1+(m/x);
            cout<<ans;
            return 0;
        }
        if(m%10<8){
            int y=(m%10)+2;
            int ans=1+(y/x);
            cout<<ans;
        }
}

#include <bits/stdc++.h>
using namespace std;
typedef int long long ll;
int main()
{
        int x,c=0;
        cin>>x;
        int h,m;
        cin>>h>>m;
        while(!(h%10==7||h/10==7||m%10==7||m/10==7))
        {
            c++;
            m-=x;
            if(m<0)
            {
                h--;
                m=m+60-x;
            }
            //cout<<h<<" "<<m<<endl;
        }
    cout<<c;

        return 0;

}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define endl "\n"
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define PB push_back
#define f(i,a,b) for(int i=a;i<b;i++)
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
   int h,m,x;
   cin>>x>>h>>m;
   if(h%10==7 || m%10==7)cout<<0;
   else
   {
       int c=0;
       while(true)
       {
           if(x>m)
           {
               m+=(60%x);
               h--;
               c++;
           }
           else m-=x,c++;
           if(m==0)m=60;
           if(h==0)h=24;
           if(h%10==7 || m%10==7)break;
       }
       cout<<c;
   }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{

 int x;
    cin>>x;
    int hh,mm;
    cin>>hh>>mm;
    int c=hh;
    int count=0;
    while(c!=0)
    {
        if(c%10==7)
        {
            cout<<"0";
            exit(0);
        }
        c/=10;
    }
     c=mm;
    while(c!=0)
    {
        if(c%10==7)
        {
            cout<<"0";
            exit(0);
        }
        c/=10;
    }
    while(1)
    {
        int d=mm-x;
        mm-=x;

        count++;
        if(d==0)
        {
            hh--;
            if(hh==7||hh==17)
            {
                cout<<count;
                exit(0);
            }
            mm=59;
        }
        if(d<0)
        {
            hh--;
            if(hh==7||hh==17)
            {
                cout<<count;
                exit(0);
            }
            mm=59;
            mm+=d;
        }
        while(d!=0)
        {
            if(d%10==7)
        {
            cout<<count;
            exit(0);
        }
        d/=10;
        }

    }

    return 0;
}

	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define ld long double
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	using namespace std;
	bool seven(int x)
	{

		while(x != 0)
		{
			int digit = x%10;
			if(digit == 7)
				return true;
			x /=10;
		}
		return false;

	}
	int main()
	{
		std::ios::sync_with_stdio(false);
		int T;
		/*cin>>T;*/
		T = 1;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			ll i,j,k;
			string s = "";
			ll x,hh,mm;
			cin>>x>>hh>>mm;
			ll newh;
			if(seven(hh) || seven(mm))
				cout<<"0"<<endl;
			else
			{
				if(mm !=0)
				{
					for(i=mm;i>=0;i-=x)
					{
					if(seven(i))
						{cout<<((mm - i)/x)<<endl;
							return 0;
						}
					}
				}
				if(i < 0 || mm == 0)
				{
					if(hh == 0)
						newh = 23;
					else
					newh = hh -1;
					if(seven(newh))
						cout<<mm/x<<endl;
					else
					{
					for(i=mm;i>=0;i-=x)
					{
					if(seven(i))
						{	cout<<((mm - i)/x)<<endl;
							return 0;
						}
					}
					}
				}

		}
	}
		return 0;
	}

// Bismillahir Rahmanir Rahim

#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> pll;
typedef pair <ll, pll> plp;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;

const int MX = 2e6+10;
const int mod = 1e9 + 7;
const ll inf = 1LL << 62;

int dx4[] = { 0, 0, -1, 1 };
int dy4[] = { 1, -1, 0, 0 };

int dx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
int dy[] = { 1, 0, -1, 1, -1, 1, 0, -1 };

// TOOLS
#define LCM(a,b)        (a / __gcd(a,b) ) *b
#define gcd(a,b)        __gcd(a,b)
#define all(x)          (x).begin(), (x).end()
#define mem(a, n)       memset(a, n, sizeof(a))
#define for1(i, n)      for(int i=1; i<=n; i++)
#define for0(i, n)      for(int i=0; i<n; i++)
#define rof0(i, n)      for(int i=n-1; i>=0; i--)
#define rof1(i, n)      for(int i=n; i>=1; i--)
#define forab(i, a, b)  for(int i=a; i<=b; i++)
#define rofab(i, a, b)  for(int i=b; i>=a; i--)
#define pb              push_back
#define pbb             pop_back

// CIN/COUT
#define YES             cout << "YES" << endl
#define NO              cout << "NO" << endl
#define sin(s)          getline(cin, s)
#define scf(a)          cin >> a
#define scf2(a, b)      cin >> a >> b
#define scf3(a, b, c)   cin >> a >> b >> c
#define scf4(a,b,c,d)   cin >> a >> b >> c >> d
#define pnf(a)          cout << (a) << endl
#define pnf2(a, b)      cout << (a) << " " << (b) << endl
#define pnf3(a, b, c)   cout << (a) << " " << (b) << " " << (c) << endl
#define bug(n)          cout << ">> " << n << " <<" << endl
#define line            cout << "==========" << endl
#define pnfa(a)         cout << (a) << " "
#define pf(a)           cout << (a)
#define sp              cout << " "
#define nl              cout << endl

// SCANF/PRINTF
#define fYES            printf("YES\n")
#define fNO             printf("NO\n")
#define Sin(s)          gets(s)
#define Scf(a)          scanf("%lld", &a)
#define Scf2(a, b)      scanf("%lld %lld", &a, &b)
#define Scf3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define Scf4(a,b,c,d)   scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
#define Pnf(a)          printf("%lld\n", a)
#define Pnf2(a, b)      printf("%lld %lld\n", a, b)
#define Pnf3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define Bug(n)          printf(">> %lld <<\n", n)
#define Line            printf("==========\n")
#define Pnfa(a)         printf("%lld ", a)
#define Pf(a)           printf("%lld", a)
#define Sp              printf(" ")
#define Nl              printf("\n")

// OTHERS
#define saz(n)          n.size()
#define clr(v)          v.clear()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define in              freopen("input.txt", "r", stdin)
#define out             freopen("output.txt", "w", stdout)
#define FastIO          { ios_base::sync_with_stdio(false); cin.tie(0); }
#define F               first
#define S               second
#define mpp             make_pair

//string s;
//vector<ll> v;
//vector<ll> v[MX];
//ll ar[MX], br[MX];
//ll vist[MX];
//map<ll,ll> mp;

int main()
{
    ll x, hh, mm;
    ll mx = inf, mn = inf;
    string h, m;
    scf3(x, h, m);
    ll cnt=0;
    hh = h[0] - '0';
    hh = hh * 10 + h[1] - '0';
    mm = m[0] - '0';
    mm = mm * 10 + m[1] - '0';
    if(h[0]=='7'||h[1]=='7'||m[0]=='7'||m[1]=='7'){
        return pnf(0),0;
    }
    ll cur = 0;
    while(true){
        mm--;
        if(mm < 0){
            hh--;
            mm=59;
        }
        if(hh < 0){
            hh=23;
        }
        cur++;
        if(cur >= x){
            cur = 0;
            cnt++;
        }

//        cout << cur << " " << cnt << endl;
//        cout << hh << " " << mm << endl;
//        cout << endl;
        ll a = hh % 10;
        ll b = mm % 10;

        if(a == 7 || b == 7){
            cout << cnt << endl;
            return 0;
        }

    }
    return 0;
}

#include<iostream>
#define ll long long
using namespace std;
int main()
{
    ll x;
    cin>>x;
    ll hrs,min;
    cin>>hrs>>min;
    if(hrs%10==7)
    {
        cout<<"0";
        return 0;
    }

    if(min%10==7)
    {
        cout<<"0";
        return 0;
    }

    ll steps=0;
    while(1)
    {
         if(min%10==7 || hrs%10==7)
         {
             break;
         }

         if(min==0)
         {
             hrs--;
             if(hrs==-1)
             {
                 hrs=23;
             }
             min=59;
             steps++;
             continue;
         }
        min--;
        steps++;
    }

    ll ans=steps/x;
    if(steps%x!=0)
    {
        ans++;
    }

    cout<<ans;
    return 0;
}

/*
   #
  # #    #    #   ####   #    #  #    #
 #   #   ##   #  #       #    #  #    #
#     #  # #  #   ####   ######  #    #
#######  #  # #       #  #    #  #    #
#     #  #   ##  #    #  #    #  #    #
#     #  #    #   ####   #    #   ####

*/
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp>
  #include <ext/pb_ds/tree_policy.hpp>
  #define int long long int
  #define hell 1000000007
  #define F first
  #define re 15000000
  #define S second
  #define pb push_back
  #define all(a)  (a).begin(),(a).end()
  #define rep(i,a,b) for(int i = a;i<b;i++)
  #define pi 3.1415926536
  #define Mod 998244353
  #define endl '\n'
  #define TIME  cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
  #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  using namespace std;
  using namespace __gnu_pbds;
  int binarySearch(int x,int y ,int z ,int v[])
    {
        int low = x;
        int high = y;
        int mid = x+(y-x)/2;
        while(low<=high)
        {
            if(v[mid]==z)
                return mid;
            if(v[mid]<z)
                return binarySearch(mid+1,high,z,v);
            if(v[mid]>z)
                return binarySearch(low,mid-1,z,v);
        }
        return -1;
    }
  int modularExponentiation(int x, int y, int m)
  {
      if (y == 0)
          return 1;
      int p = modularExponentiation(x, y/2, m) % m;
      p = (p * p) % m;

      return (y%2 == 0)? p : (x * p) % m;
  }
    int binaryExponentiation(int x,int n)
    {
        if(n==0)
            return 1;
        else if(n%2 == 0)        //n is even
            return binaryExponentiation(x*x,n/2);
        else                             //n is odd
            return x*binaryExponentiation(x*x,(n-1)/2);
    }

    set<string> s;
    //vector<int> v;
    void genrate(string n,int len,int max)
    {
        if(n.size() == max){
          s.insert(n);
          return ;
        }
        genrate(n+'1',len+1,max);
        genrate(n+'0',len+1,max);
    }
    // bool visited[200005];
    // vector<int> v[200005];
    // bool recur[200005];
    // int c = 0;
    // void dfs(int x ,int parent)
    // {
    //    visited[x] = 1;
    //    if(v[x].size() != 2)
    //     c = -1;
    //    for(int i = 0;i<v[x].size();i++){
    //     if(v[x][i] == parent)
    //       continue;
    //     if(visited[v[x][i]] && v[x].size() == 2 && c ==  0)
    //         c = 1;
    //     else if(!visited[v[x][i]]){
    //      dfs(v[x][i],x);
    //    }
    //    //return false;
    //     }
    // }
    //memset(level,0,sizeof(level));
    //char a2001][2001];
    ///**************** Cycle using DSU *********************///
  /* int topological_sort(int x)
  {
     vis[x] = 1;
     sort(all(v[x]));
     ans.pb(x);
     last[x] = x;
      for(int i =0;i<v[x].size();i++)
      {
          if(vis[v[x][i]]!=1){
              last[x] = topological_sort(v[x][i]);
          }
      }
      return last[x];
  }
*/
  int my_lower(vector<int> &v, int X){
    int lo = 0, hi = v.size()-1;
    if(v.size() == 0)
      return -1;
    while(hi-lo > 1){
      int mi = (lo+hi)/2;
      if(v[mi] < X){
        lo = mi;
      }
      else
        hi = mi-1;
    }
    int ans = -1;
    for(int i = lo;i<=hi;i++){
      if(v[i] < X){
        ans = i;
      }
    }
    if(ans != -1 && v[ans] < X){
      return ans;
    }
    else
      return -1;
  }
  int my_upper(vector<int> & v, int X){
    if(v.size() == 0)
      return -1;
     int lo = 0, hi = v.size()-1;
    while(hi-lo > 1){
      int mi = (lo+hi)/2;
      if(v[mi] < X){
        lo = mi+1;
      }
      else
        hi = mi;
    }
    int ans = -1;
    for(int i = hi;i>=lo;i--){
      if(v[i] >= X){
        ans = i;
      }
    }
    if(ans != -1 && v[ans] >= X){
      return ans;
    }
    else
      return -1;
}
int findlcm(int arr[], int n)
{
    // Initialize result
    int ans = arr[0];

    // ans contains LCM of arr[0], ..arr[i]
    // after i'th iteration,
    for (int i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (__gcd(arr[i], ans)));

    return ans;
}
vector<int> get(int h, int m, int x){
  m = m+x;
  if(m >= 60){
    m = m-60;
    h++;
    if(h >= 24)
      h = h-24;
  }
  return {h, m};
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //std::setprecision(20);
    int tests=1;
    //freopen("input.txt", "r", stdin);
    // cin>>tests;
    while(tests--)
    {
      int x;
      cin>>x;
      int h,m;
      cin>>h>>m;
      int ans = hell;
      for(int i=0;i<24;i++){
        for(int j = 0;j<60;j++){
          if((i == 7 || i == 17) || (j == 7 || j == 17)){
            int cnt = 0;
            int total = 0;
            int f = 0;
            int hr = i, mi = j;
            while(total < 1440){
              if(hr == h && mi == m){
                f = 1;
                break;
              }
              total = total+x;
              cnt++;
              vector<int> res = get(hr, mi, x);
              // cout<<res[0]<<" "<<res[1]<<endl;
              hr = res[0];
              mi = res[1];
            }
            if(f){
              // cout<<i<<" "<<j<<endl;
              ans = min(ans, cnt);
            }
          }
        }
      }
      cout<<ans<<endl;
    }

}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <stack>
#include <cstdio>

using namespace std;

const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = INF + 7;
const long long EPS = 1e-9;

long long a, b, x, t, sum, ho, mi, ans;
string h, m;

int main() {

	cin >> x;
	cin >> h >> m;

	if (h[0] == '0')
		ho = h[1] - '0';
	else
		ho = int((h[0] - '0')) * 10 + int(h[1] - '0');

	if (m[0] == '0')
		mi = m[1] - '0';
	else
		mi = int((m[0] - '0')) * 10 + int(m[1] - '0');

	while (mi % 10 != 7 && ho % 10 != 7) {
		mi -= x;
		if (mi < 0) {
			mi *= -1;
			mi %= 60;
			ho--;
		}
		if (ho < 0)
			ho = 23;
		ans++;
	}

	cout << ans;

	//system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t=0,ct=0;
    cin>>n;
    int hh,mm;
    cin>>hh>>mm;

    while(t=0)
    {
        cout<<hh<<" "<<mm<<endl;
        if(hh%7==0||mm%7==0)
        {
        t=1;
        break;
        }
        else
        {
            if(mm-n>0)
            {
            mm=mm-n;
            ct++;
            }
            else if(mm-n<0 && hh>0)
            {
                mm=mm+60-n;
                hh=hh-1;
                ct++;
            }
            else if(hh=0)
            {
                mm=mm+60-n;
                hh=23;
                ct++;
            }

        }
    }
    cout<<ct;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int x, hh, mm, ans=0;
    cin>>x>>hh>>mm;
    int h=hh;
    while(h){
        if(h%10==7){
            cout<<ans<<endl;
            return 0;
        }
        h/=10;
    }
    while(true){
        if(mm==7||mm==17||mm==27||mm==37||mm==47||mm==57)
            break;
        mm-=3;
        if(mm<=0)
            mm+=60;
        ans++;
    }
    cout<<ans<<endl;

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x,ahh,amm,hh,mm;
    scanf("%d",&x);
    scanf("%d%d",&ahh,&amm);
    int t=0;
    for(hh=ahh,mm=amm;(hh%10!=7&&mm%10!=7)||t%x!=0;mm--,t++)
    {
        if(mm==-1) {mm=59;hh--;}
        if(hh==-1) {hh=23;}
        if(hh%10==7) break;
    }
    if(ahh%10==7||amm%10==7) printf("0");
    else if(hh%10==7) printf("%d\n",t/x+1);
    else printf("%d\n",t/x);
    return 0;
}

#include <iostream>

using namespace std;
int x,h,m,tot;

bool isLucky(int a, int b)
{
    if (a%10==7 || a/10==7 || b%10==7 || b/10==7)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int abs(int a)
{
    if (a<0)
    {
        return 0-a;
    }
    else
    {
        return a;
    }
}

void windBack(int mi)
{
    int hi = abs((60-(m-mi))/60);
    if (m-mi<0)
    {
        m = 60-abs((m-mi)%60);
    }
    else
    {
        m = abs((m-mi)%60);
    }
    h = abs((h-hi)%24);
}

int main()
{
    cin >> x;
    cin >> h >> m;
    int tot = 0;
    if (x%2==0 && m%2==0) {cout << x;return 0;}
    while (isLucky(h, m)==false)
    {
        windBack(x);
        //cout << h  << ":" << m << "\n";
        tot++;
    }
    cout << tot;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>

/* A. Jamie and Alarm Snooze */

using namespace std;
typedef long long ll;

int main(int argc, char * argv[])
{
	int x, tim, h, m;
	char hh[3], mm[3];

	scanf("%d", &x);
	getchar();
	scanf("%s%s", hh, mm);
	for (int i = 0; i < 2; i ++)
	{
		if (hh[i] == '7' || mm[i] == '7')
		{
			printf("0\n");
			return 0;
		}
	}
	h = (hh[0] - '0') * 10 + hh[1] - '0';
	m = (mm[0] - '0') * 10 + mm[1] - '0';
	if (m < 7)
	{
		if (hh[1] == '8')
			tim = m + 1;
		else
			tim = m + 3;
	}
	else
	{
		if (mm[1] > '7')
		{
			tim = mm[1] - '7';
		}
		else
			tim = 10 + mm[1] - '7';
	}
	int res;
	if (tim % x)
		res = tim / x + 1;
	else
		res = tim / x;
	printf("%d\n", res);
    return 0;
}

/* SPARROW 2018 */
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long

#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)

#define pfi(x) printf("%d",x)
#define pfl(x) printf("%lld",x)
#define pfd(x) printf("%lf",x)
#define pfc(x) printf("Case %d: ",x++)
#define ps printf(" ")
#define pn printf("\n")
#define pb(x) push_back(x)
#define ppb(x) pop_back(x)
#define pf(x) push_front(x)
#define ppf(x) pop_front(x)
#define in(x,y) insert({x,y})
#define sv(a) sort(a.begin(),a.end())
#define mx

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("1015.txt","w",stdout);
    //cout<<"YES"<<"\n";
    //cout<<"NO"<<"\n";
    int x,hh,mm;
    sci(x);
    sci(hh);sci(mm);

    if(hh%10==7 || mm%10==7) {
        cout<<"0"<<"\n";
        return 0;
    }
    int cnt=mm,ans;
    int j=0;
    while(1){
        cnt--;
        if(cnt<0){
            cnt=59;
            hh--;
            if(hh<0) hh=23;
            j++;
        }
        if(j>1) ans=(60 *(j-1))+mm;
        else if(j==1) ans=(mm)+(60-cnt);
        else ans=mm-cnt;
// cout<<"ll"<<" "<<hh<<" "<<ans<<" "<<cnt<<endl;
        if(hh%10==7 && ans%x==0) break;
        //cout<<"KK"<<endl;
        //cout<<cnt%10<<" "<<ans%x<<endl;
        if(cnt%10==7 && ans%x==0 )break;
    }
   //cout<<ans<<endl;
    cout<<ans/x;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define FastRead            ios_base::sync_with_stdio(0);cin.tie(0);
int main()
{
    FastRead;
    int c=0,p=0,m=0,n=0;
    scanf("%d",&p);
    scanf("%d %d",&m, &n);
    while(1)
    {
        if (m%10==7 || m/10==7 || n%10==7 || n/10==7)
        break;
        if(n<=0)
        {
            n=n+60;
            m=m-11;
        }
        if(n<=0)
        {
            n=n+24;
        }
        n=n-3;
        c++;

    }
    printf("%d",c);
    return 0;
}

//916A
#include <iostream>

bool check_time(int t) {
	while (t > 0) {
		if (t % 10 == 7) return true;
		t /= 10;
	}
	return false;
}

int main() {
	int x, y = 0, hh, mm, h0, m0;

	std::cin >> x;
	std::cin >> hh >> mm;

	h0 = hh;
	m0 = mm;

	while (!check_time(m0)) {
		y++;
		m0 -= x;
		if (m0 < 0) {
			m0 = 60 - abs(m0);
			h0--;
			if (h0 < 0) h0 = 23;
			if (check_time(h0)) break;
		}

	}

	std::cout << y << std::endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fir first
#define se second
const int maxn = 2e5+10;
typedef pair<int,int> pii;

int check(int x) {
	if(x%10 == 7) return 1;
	return 0;
}

int main() {
	int x,h,m,ma;
	cin>>x>>h>>m;
	int cnt = 0,ff = 0;
	for(int i = h;;i--) {
		if(i < 0) i += 24;
		if(i == h) ma = m;
		else ma = 59;
		for(int j = ma;j >= 0;j--) {
			if(check(j) || check(i) && cnt % x == 0){
				ff = 1;
				break;
			}
			cnt++;
			//cout<<i<<"-"<<j<<endl;
		}
		if(ff) break;
	}
	//cout<<cnt<<endl;
	cout<<cnt/x<<endl;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
	int x, h, m, hh, mm, sum, cnt;
	cin >> x;
	cin >> h >> m;
	hh = h;
	mm = m;
	sum = h * 60 + m;
	cnt = 0;
	while (hh % 10 != 7 && mm % 10 != 7){
		sum -= x;
		if (sum < 0) sum += 3600;
		hh = sum / 60;
		mm = sum % 60;
		cnt++;
	}
	cout << cnt << '\n';
	return 0;
}

/*
 * https://codeforces.com/contest/916/problem/A
 */

#include <bits/stdc++.h>

using namespace std;

bool has7(int a, int b) {

	return (a % 10 == 7 || b % 10 == 7);

}

int num_snoozes (int k , int h , int m){

	int c = 0;

	while(!has7(h,m)){
		if (m > k) m -= k ;
		else {
			m += 60 -k;
			h--;
			if (h == -1) h = 23 ;
		}
		c++;
	}

	return c;
}

int main() {

	int k , h , m ;
	scanf("%d%d%d",&k,&h,&m);

	printf("%d\n",num_snoozes(k, h, m));

	return 0;

}

#include <stdio.h>
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
	int time;
	cin >> time;
	int hh, mm;
	cin >> hh >> mm;
	int result = 0;
	int i = mm;
	while (1)
	{
		if (hh == 7 || hh == 17)
		{
			cout << result;

			return 0;
		}
		for (; i > 0; i -= time)
		{
			if (i % 10 == 7)
			{
				cout << result;

				return 0;
			}
			else
			{
				result++;
			}
		}
		i += 60;
		hh--;
		if (hh < 0)
			hh = 23;
	}
}

#include<bits/stdc++.h>
using namespace std;
int x,hh,mm,s;
bool xy(int n,int m)
{
	while(n)
	{
		if(n%10==7) return true;
		n/=10;
	}
	while(m)
	{
		if(m%10==7) return true;
		m/=10;
	}
	return false;
}
int main()
{
	cin>>x>>hh>>mm;
	while(!xy(hh,mm))
	{
		mm-=x;
		if(mm<0)
		{
			hh--;
			mm=60-abs(mm);
		}
		if(hh==0) hh=23;
		s++;
	}
	cout<<s;
	return 0;
}

#include <iostream>
#include<conio.h>
#include<math.h>
#include<stdio.h>

using namespace std;

int main()
{
    int x,m,h,count=0,y;
    cin>>x;
    cin>>h>>m;
    for(int i=1;;i++)
    {
        if(y%10==7 || y/10==7 || m%10==7 || m/10==7)
        {
            break;
        }
        m = m-x;
        if(m<0)
        {
            m = 60+m;
            --h;
            y=fabs(h);
            ++count;
        }
        else
        {
            ++count;
        }
    }
    cout<<count<<endl;
}

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
long long int MOD =1000000007;
#define MODL 1000000000000000003
#define pb push_back
#define ll long long int
#define llu long long unsigned int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define mp make_pair
#define vs vector<string>
#define ms(x, v) memset(x, v, sizeof x)
#define fr(i, a, b) for(int i=a; i<=b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define ft first
#define sd second
#define tr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define all(c) (c.begin()),(c.end())
#define present(c,x)     ((c).find(x) != (c).end())
#define cpresent(c,x)    (find(all(c),x) != (c).end())
using namespace std;
template <class T>inline void sary(T* st, T* nd){while(st<nd)cin>>*st++;}
template <class T>inline double sarys(T* st, T* nd,T sum){while(st<nd){cin>>*st++;sum+=*st;} return sum;}
template <class T>inline void saryp(T* st, T* nd){while(st<nd){cout<<*st++<<" ";}cout<<endl;}
#define err(x) cout<<#x"="<<x<<endl
#define err2(x,y) cout<<#x"="<<x<<" "#y"="<<y<<endl
#define err3(x,y,z) cout<<#x"="<<x<<" "#y"="<<y<<" "#z"="<<z<<endl
#define sc(x) scanf("%d",&x)
#define pf(x) printf("%d\n",x)
#define endl "\n"
#define w(t) while(t--)
#define scc(x,y) scanf("%d%d",&x,&y);
#define sccc(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define fiz ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pY printf("Yes\n")
#define pN printf("No\n")
#define frv(i,a,b,v) for(int i=a;i<=b;i=i+v)
#define frc(i,a,b,cond) for(int i=a;i<=b && cond;i++)
#define MIN -10000000000000
#define ld long double
const int N=1e6+5;
#define vec(v,it) for(vector<int> ::iterator it=v.begin();it!=v.end();it++)
#define set(s,it) for(set<int> ::iterator it=s.begin();it!=s.end();it++)
#define map(m,it) for(map<int,int> ::iterator it=m.begin();it!=m.end();it++)
int root(int arr[],int i)
{
    while(arr[i]!=i)
        i=arr[i];
    return i;
}
void weighted_union(int arr[],int n,int size[],int x,int y)
{
    int root_a=root(arr,x);
    int root_b=root(arr,y);
    if(root_a==root_b)
        return;
    if(size[root_a]<size[root_b])
    {
        arr[root_a]=root_b;
        size[root_b]+=size[root_a];
    }
    else
    {
        arr[root_b]=root_a;
        size[root_a]+=size[root_b];
    }
}

bool isd(int x)
{
    while(x)
    {
        int d=x%10;
        if(d==7)
            return true;
        x/=10;
    }
    return false;
}
int main()
{
    int x;
    cin>>x;
    int h,m;
    cin>>h>>m;
    if(isd(h) || isd(m))
    {
        cout<<0<<endl;
        return 0;
    }
    if(m<7)
    {
        int ans=m+3;
        ans=ceil((double)ans/x);
        cout<<ans<<endl;
        return 0;
    }
    if(m<17)
    {
        int ans=m-7;
        ans=ceil((double)ans/x);
        cout<<ans<<endl;
        return 0;
    }
    int d=m/10;
    d--;
    d=d*10+7;
    int ans=m-d;
    ans=ceil((double)ans/x);;
    cout<<ans<<endl;
    return 0;

    }

#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n;
    int a,b;
    cin>>n;
    cin>>a>>b;
    int ans=0;
    for(;;)
    {
        if(a%10==7||a/10%10==7||b/10%10==7||b%10==7)
        {
            break;
        }
        b--;
        ans+=1;
        if(b==-1)
        {
            b=59;

            if(a==0)
                a=23;
            else
                a--;
        }
    }
    cout<<ans/n<<endl;

}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int x, h, m;
int main()
{
	while (~scanf("%d%d%d", &x, &h, &m))
	{
		if (h % 10 == 7 || h / 10 % 10 == 7 || m % 10 == 7 || m / 10 % 10 == 7) {
			cout << 0 << endl;
			continue;
		}
		int ans1=0, ans2=0, tmp=m,g=h;
		while (1) {
			ans1++;
			if (tmp < x) tmp = tmp + 60 - x,g--;
			else tmp -= x;
			if (g < 0) g = 23;
			if (tmp % 10 == 7 || tmp / 10 % 10 == 7||g%10==7||g/10%10==7) break;
		}
		tmp = m; g = h;
		while (1) {
			ans2++;
			if (tmp + x >= 60) g++, tmp = (tmp + x) % 60;
			else tmp += x;
			if (g > 23) g = 0;
			if (tmp % 10 == 7 || tmp / 10 % 10 == 7 || g % 10 == 7 || g / 10 % 10 == 7) break;
		}
		//cout << ans1 <<' '<< ans2 << endl;
		cout << min(ans1, ans2) << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define f(i,n) for( ll (i)= 0;(i)<(n);(i)++)
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define lp pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define M_H priority_queue<lp ,vector<lp >,greater<lp > >
#define rep(i,j,n) for( ll (i)= j;(i)<(n);(i)++)

int main()
{
    faster;
    ll x,h,m,a,b,c,d,u,cnt=0,hh,v;
    cin>>x;
    cin>>h>>m;
    a=h/10;
    b=h%10;
    c=m/10;
    d=m%10;
    if(a==7||b==7||c==7||d==7)
    {
        cout<<"0"<<endl;
        return 0;
    }
    hh=h;
    for(ll i=m; ; i+=x)
    {
        //cout<<hh<<" "<<i<<endl;
        a=i/10;
        b=i%10;
        c=hh/10;
        d=hh%10;
        if(a==7||b==7||c==7||d==7)
        {
            u=cnt;
            break;
        }
        if(hh==23 && i==59)
        {
            hh=0;
            i=0;
        }
        if(i>=60 && hh<=23)
        {
            hh=hh+1;
            i=i-60;
        }
        if(hh>23)
            break;
        cnt++;
    }
//cout<<u<<endl;
    cnt=0;
    hh=h;
    for(ll i=m; ; i-=x)
    {
        a=i/10;
        b=i%10;
        c=hh/10;
        d=hh%10;
        if(a==7||b==7||c==7||d==7)
        {
            v=cnt;
            break;
        }
        if(i==0 && hh==0)
        {
            i=23;
            hh=59;
        }
        if(i<=0)
        {
            i+=60;
            hh=hh-1;
        }
        if(hh<0)
        {
            break;
        }
        cnt++;
    }
//cout<<v<<endl;
    cout<<min(u,v)<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define fill(a,v) memset(a,v,sizeof a)
#define pb push_back
#define ff first
#define ss second
using namespace std;
ll i,j,n;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll x;
	cin>>x;
	ll a,b;
	cin>>a>>b;
	ll p=-1;
	if(b>=7 && b<17)
		p=7;

	if(b>=17 && b<27)
		p=17;

	if(b>=27 && b<37)
		p=27;

	if(b>=27 && b<37)
		p=37;

	if(b>=37 && b<47)
		p=37;

	if(b>=47 && b<57)
		p=47;
	if(p!=-1)
	{
		ll ans=abs(b-p);
		ans/=x;
		cout<<ans;
		return 0;
	}

	if( (b>=57 && b<=59))
	{
		p=57;
		ll ans=abs(b-p);
		ans/=x;
		cout<<ans;
		return 0;
	}
	if(b>=0)
	{
		ll ans=b+3;
		ans/=x;
		cout<<ans;
		return 0;
	}

  return 0;
  }

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <unordered_map>
#include <map>
#include <queue>

#define ll long long

using namespace std;

int main() {
    int x, h, m;
    cin >> x >> h >> m;
    int hh = h, mm = m;
    while (true) {
        if (h == 0 && m == 0) {
            hh += 24;
            h = 23;
            m = 59;
        }
        if (h == 7 || h == 17 || m == 7 || m == 17 || m == 27 || m == 37 || m == 47 || m == 57) {
            int time = hh * 60 + mm - (h * 60 + m);
            cout << time / x + (time % x == 0 ? 0 : 1);
            break;
        }
        --m;
        if (m < 0) {
            m = 59;
            --h;
        }
    }
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int x, h, m, c=0;
    cin>>x>>h>>m;
    while(1)
    {
        if((h%10==7) || ( m%10==7))
            break;
        if(m-x>0)
            m=m-x;
        else
        {

            m=60+m-x;
            if(h-1>0)
                h--;
            else
            {
                h+=23;
            }

        }
        c++;
    }
    cout<<c<<endl;

}

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
	int k;
	int x,y,sum,ans;
	scanf("%d%d%d",&k,&x,&y);
	if(y>=57)
	{
		sum=y-57;
	}
	else if(y>=47&&y<57)
	{
		sum=y-47;
	}
	else if(y>=37&&y<47)
	{
		sum=y-37;
	}
	else if(y>=27&&y<37)
	{
		sum=y-27;
	}
	else if(y>=17&&y<27)
	{
		sum=y-17;
	}
	else if(y>=7&&y<17)
	{
		sum=y-7;
	}
	else
	{
		sum=y+3;
	}
	ans=(sum)/k;
	if(x==17||x==7)
	{
		ans=0;
	}
	if(x==18||x==8)
	{
		ans=min((y+1)/k,ans);
	}
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main()
{
    int x;
    string a,b;
    scanf("%d",&x);
    cin>>a>>b;
    long long ans=0;
    if(a[1]=='7'||b[1]=='7')
        printf("0\n");
    else{
            int sum_m=b[1]-'0'+10*(b[0]-'0');
            int sum_h=a[1]-'0'+10*(a[0]-'0');
            while(1)
            {
                if(sum_m<=0)
                {
                    sum_m+=60;
                    sum_h-=1;
                    if(sum_h<0) sum_h=23;
                }
                sum_m-=x;
                ans++;
                if(sum_m%10==7||sum_h%10==7)
                    break;
            }
            printf("%I64d\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

int main() {
  int x, h, m;
  while (cin >> x >> h >> m) {
    int ans;
    if (h % 10 == 7 || m % 10 == 7) {
      ans = 0;
    } else if (h % 10 == 8 && m < 7) {
      ans = m + 1;
    } else {
      ans = 0;
      while (m % 10 != 7) {
        if (!m) {
          ans += 3;
          break;
        }
        m--;
        ans++;
      }
    }
    cout << (ans / x + (ans % x == 0 ? 0 : 1)) << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int x;
    cin>>x;
    int h,m;
    cin>>h>>m;
	int y=0;
	while(h%10!=7 && m%10!=7)
	{
		m=m-x; y++;
		if(m<0)
		{
		m=60+m;
		h--;
		if(h<0)
		h=23;
	    }
	}
	cout<<y<<" "<<h<<" "<<m;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{

    int n;
    cin>>n;
    int a[n];

    for(int i=0;i<n;i++)
    cin>>a[i];

    sort(a,a+n);
    int c=0;
    for(int i=n-1;i>=0;i--)
    {
      int x=sqrt(a[i]*1.0);
      int y=sqrt(a[i]*1.0 - 1.0);
      if(x==y)
      {
        cout<<x<<" "<<y<<endl;
        c=i;
        break;
      }
    }
    cout<<" "<<a[c]<<" "<<c;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii; typedef pair<ll,ll> pll;
const int MOD = 1000000007, MOD2 = 1000000009;
const int INF = 0x7fffffff; const ll LINF = 0x7fffffffffffffff;
#define FOR(i,j,k) for(int i=(j);i<(k);i++)
#define FOI(i,j,k) for(int i=(j);i<=(k);i++)
#define ff first
#define ss second

int n;
string a,b;

int main() {
    cin>>n;
    cin>>a>>b;
    if (a.find('7')!=-1 || b.find('7')!=-1) {
        cout<<0<<'\n';
        return 0;
    }
    else {
       int i=0,j=0;
       string a1=a,b1=b,a2=a,b2=b;
       while (a1.find('7')==-1 && b1.find('7')==-1 && a2.find('7')==-1 && b2.find('7')==-1) {
           i++;
           j++;
           b1=to_string(stoi(b1)+n);
           b2=to_string(stoi(b2)-n);
           if (stoi(b1)>=60) {
               a1=to_string(stoi(a1)+1);
               b1=to_string(stoi(b1)-60);
           }
           if (stoi(a1)>=24) a1=to_string(stoi(a1)-24);
           if (stoi(b2)<0) {
               a2=to_string(stoi(a2)-1);
               b2=to_string(stoi(b2)+60);
           }
           if (stoi(a2)<0) a2=to_string(stoi(a2)+24);

       }
       cout<<min(i,j)<<'\n';
       return 0;
    }
    return 0;
}

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
	int x,h,m,count=0; char hh[3],mm[3];
	cin>>x;
	cin>>hh>>mm;
	if(hh[0]=='7' ||hh[1]=='7' ||mm[0]=='7' ||mm[1]=='7' )
	{
		cout<<0;
	}
	else
	{
		h=atoi(hh);
		m=atoi(mm);
		while(1)
		{
			if(m>0)
			{
				if(m%10==7)
				{
					cout<<count;
					break;
				}
				else
				{
					count=count+1;
				}
				m=m-x;
			}
			else
			{
				h=h-1;
				if(h%10==7 && h>0)
				{
					count+=1;
					cout<<count;
					break;
				}
				if(h<0)
				{
					h=24+h;
				}
				m=60+m;
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int x ;
    cin >> x ;
    int h , m ;
    cin >> h >> m ;
    if(h==0)
        h=24;
    int counter = 0 ;
    int a = h , b = m ;
    while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
    while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
    while(h){
        cout << h << " " << m << endl;
        bool ans = false ;
        if(m>=x){
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
        else {
            if(h>1)
                h--;
            else
                h = 12 ;
            m=60+m;
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
char c='7';
int main()
{
    ll n,h,m,cnt=0;
    cin>>n>>h>>m;
    while(1)
    {
        ll ans=h*100+m;
        cout<<ans<<" ";
        string x=to_string(ans);
       size_t found=x.find(c);
        if(found!=-1)
            break;
        else cnt++;
        m-=n;
        if(m<0)
        {
            m=60+m;
            h--;

        }
        if(h<0) {h+=24;}

    }
    cout<<cnt;
    return 0;
}

#include<iostream>
#define ll long long
using namespace std;
int main()
{
    ll x;
    cin>>x;
    ll hrs,min;
    cin>>hrs>>min;
    if(hrs%10==7)
    {
        cout<<"0";
        return 0;
    }

    ll tmp=hrs/10;
    if(tmp==7)
    {
        cout<<"0";
        return 0;
    }

    if(min%10==7)
    {
        cout<<"0";
        return 0;
    }

    ll tmp2=min/10;
    if(tmp2==7)
    {
        cout<<"0";
        return 0;
    }
    ll steps=0;
    while(1)
    {
        if(min==0)
        {
            if(hrs==0)
            {
                hrs=23;
                min=59;
                steps=steps+3;
                break;
            }

            else
            {
                hrs--;
                min=59;
                steps=steps+3;
                break;

            }
        }

        if(min%10>=7)
        {
            ll diff=(min%10)-7;
            steps+=diff;
            break;
        }

        steps+=min%10;
        min=0;
    }

    ll ans=steps/x;
    cout<<ans;
    return 0;
}

#include "bits/stdc++.h"
#define ll long long
using namespace std;

int main() {
  int x;
  cin>>x;
  int h,m;
  cin>>h>>m;
  if(h%10 == 7 || m%10 == 7) {
    cout<<0<<endl;
    return 0;
  }
  else {
    int i=0;
    while(m%10 !=7 && h%10 !=7) {
      if(m-x < 0) {
        h-=1;
        if(h<0) h=h+24;
        m=m-x+60;
      }
      m-=x;
      cout<<"H : "<<h<<" M : "<<m<<" \n";
      i++;
      if(m%10 ==7 || h%10 ==7) break;

    }
    cout<<i<<endl;

  }

return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b,a1,b1;
    cin>>x>>a>>b;
    if(a==0)
        a=24;
    if(a%10==7||b%10==7)
        cout<<0<<endl;
    else
    {
        a1=a;
        b1=b;
        while(1)
        {
            b--;
            if(b<0)
                b=59;
            if(b==0)
                a--;
            if(b%10==7)
                break;
            if(a%10==7)
                break;
        }
        int cnt=1;
        while(1)
        {
            b+=x;
            if(b>=60)
            {
                a++;
                b=b-60;
            }
            if(a>=a1&&b>=b1)
            {
                break;
            }
            cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int LL;
typedef unsigned long long uLL;
typedef pair< int,int > ii;
typedef pair< int,ii > iii;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 100005;
const int MOD = 1e9+7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

bool ok( int val ) {
    while( val ) {
        int r = val%10;
        if( r == 7 ) return true;
        val /= 10;
    }
    return false;
}
int main( int argc, char const *argv[] ) {
    int x , h , m;
    cin >> x >> h >> m;
    if( ok(h) | ok(m) ) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    while( true ) {
        m --;
        ans ++;
        if( m <= 0 ) m = 59 , h--;
        if( h <= 0 ) h = 23;
        if( ok(h) || ok(m) ) break;
    }
    cout << ans/x << endl;
    return 0;
}

//// 404 Err Can't Find Code </>
/// Yazdan_Ra

#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
#include <fstream>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
#define pf pop_front
#define fr first
#define sc second
#define FIX(x) cout.precision(x)
#define sz(x) ((int)(x).size())
#define smax(x,y) ((x)=max((x),(y)))
#define smin(x,y) ((x)=min((x),(y)))
#define all(x) (x).begin(),(x).end()
#define mem(x) memset(x,0,sizeof(x))
#define connect(z,x,y) z[x].pb(y),z[y].pb(x)
#define debug1(x) cout<<string(40,'*')<<endl<< #x <<" ---> "<<x<<endl
#define debug2(x,y) cout<<string(40,'*')<<endl<< #x <<" ---> "<<x<<endl<< #y <<" ---> "<<y<<endl
#define debug3(x,y,z) cout<<string(40,'*')<<endl<< #x <<" ---> "<<x<<endl<< #y <<" ---> "<<y<<endl<< #z <<" ---> "<<z<<endl
#define debug4(x,y,z,t) cout<<string(40,'*')<<endl<< #x <<" ---> "<<x<<endl<< #y <<" ---> "<<y<<endl<< #z <<" ---> "<<z<<endl<< #t <<" ---> "<<t<<endl
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
//#define cin fin

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ld> pild;
typedef pair<double,double> pdd;
typedef unsigned long long int ull;

inline int iin() { int x; scanf( "%d" , &x ); return x; }
inline ll  lin() { ll  x; scanf( "%lld" , &x ); return x; }

const int N = 1e6+85;
const int M = 1e3+85;
const int mod = 1e9+7;
const ll pinf = LLONG_MAX;
const ll minf = LLONG_MIN;

int ans ;

pii Set( int hh , int mm )
{
    while ( true ) {
        string H = to_string( hh ) ;
        string M = to_string( mm ) ;
        if ( sz(H) == 1 )
            H = "0"+H ;
        if ( sz(M) == 1 )
            M = "0"+M ;
        if ( H[0] == '7' or H[1] == '7' or M[0] == '7' or M[1] == '7' )
            return { hh , mm } ;
        mm-- ;
        if ( mm == -1 ) {
            hh-- ;
            mm = 59 ;
        }
        if ( hh == -1 ) {
            hh = 23 ;
        }
    }
}

int32_t main()
{_
    int x; cin>>x;
    int hh,mm; cin>>hh>>mm;

    pii time = Set( hh , mm ) ;

    while ( true ) {
        if ( time.fr > hh or ( time.fr == hh and time.sc >= mm ) ) {
            return cout << ans << endl , 0 ;
        }
        time.sc += x ;
        int add = time.sc/60 ;
        time.sc %= 60 ;
        time.fr += add ;
        if ( time.fr == 24 )
            time.fr = 0 ;
        ans++ ;
    }
    return EXIT_SUCCESS ;
}

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int x, y, g;

int main() {
  cin >> g;
  cin >> x >> y;
  int ans = 2e9;
  for (int i = 0; i <= 23; i++) {
    for (int j = 0; j <= (i == 23 ? 59 : 60); j++) {
      if (i % 10 != 7 && i / 10 != 7 && j / 10 != 7 && j % 10 != 7) continue;
      int here = 0;
      int one = i * 60 + j;
      int two = x * 60 + y;
      if (one > two) {
        here += 24 * 60;
      }
      ans = min(ans, (here + abs(two - one)) / g);
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define fir first
#define se second
const int maxn = 2e5+10;
typedef pair<int,int> pii;

int check(int x) {
	if(x%10 == 7) return 1;
	return 0;
}

int main() {
	int x,h,m,ma;
	cin>>x>>h>>m;
	h += 24;
	int cnt = 0,ff = 0;
	for(int i = h;i >= 0;i--) {
		if(i == h) ma = m;
		else ma = 60;
		for(int j = ma;j >= 0;j--) {
			if(check(j) || check(i)){
				ff = 1;
				break;
			}
			cnt++;
			cout<<i<<"-"<<j<<endl;
		}
		if(ff) break;
	}
	//cout<<cnt<<endl;
	cout<<cnt/x<<endl;
}

#include<iostream>

using namespace std;

int main()
{
    int hh,mm,x;
    while(cin >> x)
    {
        cin >> hh >> mm;
        int y,flag=0;
        for(y=0;;y++)
        {
            if(hh%10 == 7){cout << y << endl;break;}
            int save=mm,cnt=0;
            save=save-x*y;
            while(save < 0)
            {
                save+=60;
                hh--;
                if(hh<0)
                {
                    hh=23;
                    cnt=1;
                }
            }
            if(save/10==7 || save%10==7)
            {
                flag=1;
                break;
            }
            if(hh<0 && cnt ==1)break;

        }
        if(flag==1)cout << y << endl;
        else break;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int x ;
    cin >> x ;
    int h , m ;
    cin >> h >> m ;
    if(h==0)
        h=24;
    int counter = 0 ;
    int a = h , b = m ;
    while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
    while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
    while(h){
        bool ans = false ;
        if(m>=x){
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
        else {
            h--;
            m=60;
            m-=x;
            counter++;
            int a = h , b = m ;
            while(a){int t = a %10 ; if(t==7){cout << counter << endl; return 0;}a/=10;}
            while(b){int t = b %10 ; if(t==7){cout << counter << endl; return 0;}b/=10;}
        }
    }
    return 0;
}

#include<iostream>

using namespace std;

int main()
{
    int hh,mm,x;
    while(cin >> x)
    {
        cin >> hh >> mm;
        int y,flag=0,cnt=0;
        for(y=0;;y++)
        {
            if(hh%10 == 7){cout << y << endl;break;}
            int save=mm;
            save=save-x*y;
            while(save < 0)
            {
                save+=60;
                hh--;
                if(hh<0)
                {
                    hh+=24;
                    cnt=1;
                }
            }
            if(save/10==7 || save%10==7)
            {
                flag=1;
                break;
            }
            if(hh<0 && cnt ==1)break;

        }
        if(flag==1)cout << y << endl;
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int k;
	int a,b;
    cin>>k;
    cin>>a>>b;
    int cnt=0;

    int y=1;
    for(;;)
    {
    	//cout<<a<<":"<<b<<endl;
    	if(b%10==7||a%10==7) break;
    	else
    	{
    		if(b>=k){ b=b-k;cnt++;continue;}
    		else
    		{
    			while(b<k)
    			{
    				b=b+60;
    				a--;
    				if(a<0) a=a+23;
				}
				b=b-k;
				cnt++;
			}

	      }
	}
	cout<<cnt<<endl;
}

#include<iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
using namespace std;

int main()
{       bool flag=false;
    int x, hour,minute;
    cin>>x>>hour>>minute;
    int time;
    /*
    string s7("7");

    int a = 1557;
    char hour1 [33];
    itoa (hour,hour1,10);
    string hour2(hour1);

    char minute1 [33];
    itoa (minute,minute1,10);
    string minute2(minute1);

    string time=hour2+minute2;
    int i=0;

    while(1)
    {     if(time.find(s7)!= string::npos){
                flag=true;
                break;
            }
        if(minute>x)
        {
            minute-=x;
            if(minute==0) hour--;
        }
        else
        {
           // int temp=(minute-x)*(-1);
           // minute=59;
            minute+=60-x;
            hour--;
            if(hour<1)
            {
                hour=24;
            }

        }

        char hour3 [33];
        itoa (hour,hour3,10);
        string hour4(hour3);

        char minute3 [33];
        itoa (minute,minute3,10);
        string minute4(minute3);

            time=hour4+minute4;

        i++;
    }
*/
 time=hour*60+minute;
for(int i=0;;i++){
       int h=time/60;
    int m=time%60;

    if(h/10==7 || h%10==7 || m/10==7 || m%10==7 ){
        cout<< i<<endl;
        break;
    }
    time-=x;
    if(time<0){
        time=time*(-1)+1400;
    }
}

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL)
#define cases ll t; cin>>t; while(t--)
#define rep(qq,pp) for(ll i=qq;i<pp;i++)

int main() {
    faster;

    int x,h,m,a,b,ans;

    cin>>x>>h>>m;
    a=h;
    b=m;

    if(h/10==7 || h%10==7 || m/10==7 || m%10==7)
        cout<<0<<endl;
    else{
        while(h/10!=7 && h%10!=7 && m/10!=7 && m%10!=7){
            m--;
            if(m==0)
                h--;
        }
        //cout<<h<<" "<<m;
        ans=abs(a-h)*60+abs(b-m);
        ans=ceil(ans*1.0/x);

        cout<<ans<<endl;
    }
}

#include <iostream>

using namespace std;
int x,h,m,tot;

bool isLucky(int a, int b)
{
    if (a%10==7 || a/10==7 || b%10==7 || b/10==7)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int abs(int a)
{
    if (a<0)
    {
        return 0-a;
    }
    else
    {
        return a;
    }
}

void windBack(int mi)
{
    int hi = abs((60-(m-mi))/60);
    if (m-mi<0)
    {
        m = 60-abs((m-mi)%60);
    }
    else
    {
        m = abs((m-mi)%60);
    }
    h = abs((h-hi)%24);
}

int main()
{
    cin >> x;
    cin >> h >> m;
    int tot = 0;
    while (isLucky(h, m)==false)
    {
        windBack(x);
        //cout << h  << ":" << m << "\n";
        tot++;
        if (tot > 60*24)
        {
            cout << x;
            return 0;
        }
    }
    cout << tot;
    return 0;
}

	#include <bits/stdc++.h>
#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define ld long double
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	using namespace std;
	bool seven(int x)
	{

		while(x != 0)
		{
			int digit = x%10;
			if(digit == 7)
				return true;
			x /=10;
		}
		return false;

	}
	int main()
	{
		std::ios::sync_with_stdio(false);
		int T;
		/*cin>>T;*/
		T = 1;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			ll i,j,k,ans = 0;
			string s = "";
			ll x,hh,mm;
			cin>>x>>hh>>mm;
			ll newh;
			if(seven(hh) || seven(mm))
				cout<<"0"<<endl;
			else
			{
				if(mm !=0 || mm >= x)
				{
					for(i=mm;i>=0;i-=x)
					{
					if(seven(i))
						{cout<<ans<<endl;
							return 0;
						}
					ans++;
					}

				}
				if(i < 0 || mm == 0 || mm <x)
				{
					if(hh == 0)
						newh = 23;
					else
					newh = hh -1;
					if(seven(newh))
						cout<<ans<<endl;
					else
					{
						i = mm;
						int a = 0;
						for(;i>=0;i--)
							{
								a++;
								if(a == x)
									{
										ans++;
										a = 0;
									}
							}
					for(i=60-a;i>=0;i-=x)
					{

					if(seven(i))
						{	cout<<ans <<endl;
							return 0;
						}
						ans++;
					}

					}
				}

		}
	}
		return 0;
	}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define INF INT_MAX //Infinity
#define MOD 1000000007
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,hh,mm;
    cin>>x>>hh>>mm;
    ll count = 0;
    bool check = (hh%10 == 7 || hh%100 == 7 || mm%10 == 7 || mm%100 == 7);
    while(!check) {
    	if(mm - 3 < 0) {
    		if(hh!=00)
    			hh--;
    		else
    			hh = 23;
    		mm -= 3 + 60;
    	}
    	else
    		mm -=3;
    	count++;
    	check = (hh%10 == 7 || hh%100 == 7 || mm%10 == 7 || mm%100 == 7);
    }
    cout<<count;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int hh;
  int mm;
  cin>>hh;
  cin>>mm;
  for(int i=0;;i++){
  if(hh==0 && mm<=0){
      hh=23;
      mm+=60;
    }
    if(mm<=0){
      hh--;
      mm+=60;
    }

    if(mm==7  || mm==17 || mm==27 || mm==37 || mm==47 || mm==57 || hh==7 || hh==17  ){
      cout<<i<<endl;
      break;
    }
    mm-=n;
    cout<<mm<<endl;

  }

  return 0;
}

#include<cstdio>
#include<iostream>
#include<cmath>
#include<time.h>
using namespace std;
int main(){
//        freopen("/Users/jikezhangping/Desktop/data.txt", "r+",stdin);
    int x,hh,mm;
    while(cin>>x>>hh>>mm){
        int cnt=0;
        while (hh%10!=7&&mm%10!=7) {
            cnt++;
            mm+=x;
            hh+=mm/60;
            mm%=60;
            if(hh>23)hh-=24;
        }
        cout<<cnt<<endl;
    }
//            cout<<"time:"<<(double)clock()/CLOCKS_PER_SEC<<endl;
    return 0;
}

#include<iostream>
#include<conio.h>
using  namespace std;
int main()
{
	int t, hh, mm;
	cin >> t >> hh >> mm;

	int  res = 0;
	while (hh % 10 != 7 && mm % 10 != 7 && (mm - mm % 10) / 10 != 7) {
		mm = mm - t;
		res ++;
		if (mm > 60) {
			hh++;
			mm = mm - 60;
		}
		if (hh > 60) {
			hh = 0;
		}

	}

	cout << res;
	return 0;
}

  #include <bits/stdc++.h>

  #define MAX 100009
  #define INF 99999999
  #define MIN -99999999
  #define in(a,b)  ( (b).find(a) != (b).end())
  #define clr(a,b) memset((a), (b), sizeof((a)))
  #define pb       push_back
  #define all(a)   a.begin(), a.end()
  #define mp       make_pair
  #define ll	long long
  #define FI	first
  #define SE second

  using namespace std;
  int n;
  int a,b;
  bool f(int s,int a){
    string st= to_string(s);
    string ss = to_string(a);
    for(char c : st){
      if(c == '7') return true;
    }
    for(char c : ss){
      if(c == '7') return true;
    }
    return false;
  }
  int main() {
    cin >> n;
    cin >> a >> b;
    int y=0;
    while(true){
      if(f(b,a)) {
        break;
      }
      b -= n*y;
      if(b <0 ) {
        b += 60;
        a--;
        if(a <= 0) a += 24;
      }
      y++;

    }
    cout << y << endl;
    return 0;
  }

#include<iostream>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(){
         int x,h,m,i,s=0,t;
         cin>>x;
         cin>>h;
         cin>>m;
         s=0;
         while(h!=7){
                 if(m%10==7||h%10==7)
                 {
                     cout<<s;
                     break;
                 }
                 else
                    {
                if((m-x)%10==7){
                        s++;
                    cout<<s;
                    break;
                }
                else
                {
                    m=m-x;
                    s++;
         if(m<0)
            m=m+60;
         h--;
         if(h<0)
             h=23;

         }
                 }
                 }

//system("pause");
return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dl double
#define llu unsigned long long int
#define scll(x) scanf("%lld",&x)
#define scd(x) scanf("%lf",&x)
#define sclu(x) scanf("%llu",&x)
#define scch(x) scanf(" %c",&x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define ppb(x) pop_back(x)
#define ppf(x) pop_front(x)
#define Pi acos(-1.0)
ll  _xor(ll a,ll b){return a^b;}
ll _and(ll a,ll b){return a&b;}
ll _or(ll a,ll b){return a|b;}
ll _not(ll a){ return ~a;}
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll ai[1000],pi[2005];
int main()
{
           #ifndef ONLINE_JUDGE
         freopen("input_cf.txt","r",stdin);
         freopen("output_cf.txt","w",stdout);
         #endif
    ll b,c=0,x,y,z,t,i,j,k,l1=0,l2=0,m,n,c1=0,c2=0,q,f=1,ans=0,ghonta=0,gap,minute=0;
   string  hh,mm;
              scll(gap);
             cin>>hh;
             cin>>mm;

                c1=1;
             for(j=hh.length()-1;j>=0;j--)
             {
             	ghonta+=(hh[j]-'0')*c1;
             	c1=c1*10;
             }
             c1=1;
            for(j=mm.length()-1;j>=0;j--)
            	{
            		minute+=(mm[j]-'0')*c1;
            		c1=c1*10;
            	}

     //cout<<ghonta<<' '<<minute;

ll minute_prev=minute,ghonta_prev=ghonta;
x=ghonta;
            	while(x!=0)
            	{
            		c2=x%10;
            		x=x/10;
            		if(c2==7)
            		{
            			l1=1;
            		}
            	}
 x=minute;
                while(x!=0)
            	{
            		c2=x%10;
            		x=x/10;
            		if(c2==7)
            		{
            			l1=1;
            		}
            	}
            	if(l1==1)
            	{
                     cout<<0;
            	}
            	else
            	{
            		l1=0;

            	for(j=minute;;j=j-gap)
            	{
            		x=j;
            		if(j<0)
            		{
            			ghonta--;
            			j=60-j;
            			minute=j;
            			x=ghonta;
                      while(x!=0)
            		{
            			c2=x%10;
            			x=x/10;
            			if(c2==7)
            			{

            				l1=1;
            				break;
            			}
            		}
            		}
                       if(l1)
                        break;
            		while(x!=0)
            		{
            			c2=x%10;
            			x=x/10;
            			if(c2==7)
            			{
            				l1=1;
            				minute=j;
            				break;
            			}
            		}
            	}
            	cout<<abs(minute_prev+ghonta_prev*60-(minute+ghonta*60))/gap;
            }

return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define INF INT_MAX //Infinity
#define MOD 1000000007
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,hh,mm;
    cin>>x>>hh>>mm;
    ll count = 0;
    ll htemp = hh/10;
    ll mtemp = mm/10;
    bool check = (hh%10 == 7 || htemp%10 == 7 || mm%10 == 7 || mtemp%10 == 7);
    while(!check) {
    	if(mm - x < 0) {
    		if(hh!=00)
    			hh--;
    		else
    			hh = 23;
    		mm -= x + 60;
    	}
    	else
    		mm -=x;
    	count++;
    	htemp = hh/10;
    	mtemp = mm/10;
    	check =(hh%10 == 7 || htemp%10 == 7 || mm%10 == 7 || mtemp%10 == 7);
    }
    cout<<count;
}

    #include <bits/stdc++.h>
    using namespace std;
    int check(int n){
    	int g;
    	while(n!=0){
    		g=n%10;
    		if (g==7){
    			return 1;
    		}
    		n=n/10;
    	}
    	return 0;
    }
    int main() {
    	int n,a,b,i,r;
    	scanf("%d",&n);
    	scanf("%d %d",&a,&b);
    	for (i=0;;i++){
    		if (check(a)==1 || check(b)==1){
    			printf("%d",i);
    			return 0;
    		}
    		b=b-n;
    		if (b<0){
    			r=n-b;
    			b=60-r;
    			a=a-1;
    			if (a<0){
    				a=23;
    			}
    		}
    	}
    	return 0;
    }

#include <iostream>
#include <string>
using namespace std;

int main()
{
	int x,y=0,hh,mm;
	string s;
	cin>>x>>hh>>mm;
	while(1)
	{
		s=((hh<10)?"0"+to_string(hh):to_string(hh))+""+((mm<10)?"0"+to_string(mm):to_string(mm));
		//s=to_string(hh)+""+to_string(mm);
		//cout<<hh<<" "<<mm<<endl;
		//cout<<s<<endl;
		if(s[0]=='7' || s[1]=='7' || s[2]=='7' || s[3]=='7') break;
		mm-=x;
		if(mm<0)
		{
			hh=hh-1<0?23:hh-1;

			mm=59+mm;
		}
		y++;
	}
	cout<<y<<endl;
	return 0;
}

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef pair<int, int> ii;
typedef long long ll;

const int N = 1000007, inf = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(false);
	int x;
	cin >> x;

	int a, b;
	cin >> a >> b;
	a = a * 60 + b;

	int ans = inf;
	for(int i = 0; i < 23; ++i) {
		for(int j = 0; j < 59; ++j) {
			if(i/10 == 7 or i%10 == 7 or j/10 == 7 or j%10 == 7) {
				int t = i * 60 + j;
				int q = a >= t? a - t : 24 * 60 - (t - a);

				ans = min(ans, (q)/x);
			}
		}
	}

	cout << ans << endl;

}