#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int main() {
	ios_base::sync_with_stdio(0);
	string s,ans;
	cin >> s;
	ans = s[0];
	for(int i = 1; i < s.length() - 1; i++){
		if (s[i] == ans[i - 1]){
			for(char x = 'a'; x <= 'z'; x++){
				if (x != ans[i - 1] && x != s[i + 1]){
					ans += x;
					break;
				}
			}
		}
		else {
			ans += s[i];
		}
	}
	int l = s.length() - 1;
	ans += s[l];
	l = ans.length();
	if (ans[l - 1] != ans[l - 2]){
		cout << ans << endl;
	}
	else {

	int l = ans.length() - 1;
	for(char x = 'a'; x <= 'z'; x++)
			if (ans[l] != x){
				ans[l] = x;
				break;
			}

		cout << ans << endl;
	}
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int main() {
	ios_base::sync_with_stdio(0);
	string s,ans;
	cin >> s;
	ans = s[0];
	for(int i = 1; i < s.length() - 1; i++){
		if (s[i] == ans[i - 1]){
			for(char x = 'a'; x <= 'z'; x++){
				if (x != ans[i - 1] && x != s[i + 1]){
					ans += x;
					break;
				}
			}
		}
		else {
			ans += s[i];
		}
	}
	int l = s.length() - 1;
	ans += s[l];

	cout << ans << endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int main() {
	ios_base::sync_with_stdio(0);
	string s,ans;
	cin >> s;
	if (s.length() <= 1){
		cout << s << endl;
		return 0;
	}
	ans = s[0];
	for(int i = 1; i < s.length() - 1; i++){
		if (s[i] == ans[i - 1]){
			for(char x = 'a'; x <= 'z'; x++){
				if (x != ans[i - 1] && x != s[i + 1]){
					ans += x;
					break;
				}
			}
		}
		else {
			ans += s[i];
		}
	}
	int l = s.length() - 1;
	ans += s[l];
	l = ans.length();
	if (ans[l - 1] != ans[l - 2]){
		cout << ans << endl;
	}
	else {

	int l = ans.length() - 1;
	for(char x = 'a'; x <= 'z'; x++)
			if (ans[l] != x){
				ans[l] = x;
				break;
			}

		cout << ans << endl;
	}
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cassert>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
#include<algorithm>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)
#define debug(x) cout << #x <<" = " << x << endl
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define printvpair(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i].first  <<" " << v[i].second << endl;
#define printv(v) for(int i = 0 ; (i) < (v.size()) ; ++i) cout << v[i] << " "; cout << endl;

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);
const int INF = 1000000000;

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

const int N = 100001;
int main() {
	ios_base::sync_with_stdio(0);
	string s,ans;
	cin >> s;
	ans = s[0];
	for(int i = 1; i < s.length() - 1; i++){
		if (s[i] == ans[i - 1]){
			for(char x = 'a'; x <= 'z'; x++){
				if (x != ans[i - 1] && x != s[i + 1]){
					ans += x;
					break;
				}
			}
		}
		else {
			ans += s[i];
		}
	}
	int l = ans.length() - 1;
	for(char x = 'a'; x <= 'z'; x++)
		if (ans[l] != x){
			ans += x;
			break;
		}

	cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
//    printf("len = %d\n",len);
    for (int i = 0;i < len - 1; ++ i)
    {

        if (s[i] == s[i + 1])
        {
            if (i == len - 2)
            {
                s[i + 1] = s[i] == 'a' ? s[i] + 1 : 'a';
            }
            else
            {
                if (s[i] == s[i + 2])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else if (s[i] + 1 == s[i + 2])
                {
                    if (s[i + 2] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i + 2] + 1;
                }
                else if (s[i + 2] == s[i] + 1)
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else
                    s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
            }

        }
        printf("i = %d s = %s\n",i,s);

    }
    puts(s);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
//    printf("len = %d\n",len);
    for (int i = 0;i < len - 1; ++ i)
    {

        if (s[i] == s[i + 1])
        {
            if (i == len - 2)
            {
                s[i + 1] = s[i] == 'a' ? s[i] + 1 : 'a';
            }
            else
            {
                if (s[i] == s[i + 2])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else if (s[i] + 1 == s[i + 2])
                {
                    if (s[i + 2] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i + 2] + 1;
                }
                else if (s[i + 2] + 1 == s[i])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else
                    s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
            }

        }
//        printf("i = %d s = %s\n",i,s);

    }
    puts(s);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
//    printf("len = %d\n",len);
    for (int i = 0;i < len - 1; ++ i)
    {
        if (s[i] == s[i + 1])
        {
            if (i == len - 2)
            {
                s[i + 1] = s[i] == 'a' ? s[i] + 1 : 'a';
            }
            else
            {
                if (s[i] == s[i + 2])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else if (s[i] + 1 == s[i + 2])
                {
                    if (s[i + 2] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i + 2] + 1;
                }
                else if (s[i + 2] = s[i] + 1)
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else
                    s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
            }

        }

    }
    puts(s);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
    for (int i = 0;i < len - 2; ++ i)
    {
        if (s[i] == s[i + 1])
        {
            if (s[i] == s[i + 2])
            {
                if (s[i] == 'z')
                    s[i + 1] = 'a';
                else
                    s[i + 1] = s[i] + 1;
            }
            else if (s[i] + 1 == s[i + 2])
            {
                if (s[i + 2] == 'z')
                    s[i + 1] = 'a';
                else
                    s[i + 1] = s[i + 2] + 1;
            }
            else
                s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
        }

    }
    puts(s);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
//    printf("len = %d\n",len);
    for (int i = 0;i < len - 1; ++ i)
    {
        if (s[i] == s[i + 1])
        {
            if (i == len - 2)
            {
                s[i + 1] = s[i] == 'a' ? s[i] + 1 : 'a';
            }
            else
            {
                if (s[i] == s[i + 2])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else if (s[i] + 1 == s[i + 2])
                {
                    if (s[i + 2] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i + 2] + 1;
                }
                else
                    s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
            }

        }

    }
    puts(s);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cctype>
#include <map>
#include <queue>
#include <cmath>
#include <set>
#include <stack>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#define pu system("pause")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1.0);
const int inf = 0x7fffffff;
const int mod = 1e9 + 7;

char s[200010];

int main()
{
    scanf("%s",s);
    int len = strlen(s);
//    printf("len = %d\n",len);
    for (int i = 0;i < len - 1; ++ i)
    {

        if (s[i] == s[i + 1])
        {
            if (i == len - 2)
            {
                s[i + 1] = s[i] == 'a' ? s[i] + 1 : 'a';
            }
            else
            {
                if (s[i] == s[i + 2])
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else if (s[i] + 1 == s[i + 2])
                {
                    if (s[i + 2] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i + 2] + 1;
                }
                else if (s[i + 2] == s[i] + 1)
                {
                    if (s[i] == 'z')
                        s[i + 1] = 'a';
                    else
                        s[i + 1] = s[i] + 1;
                }
                else
                    s[i + 1] = (s[i] + s[i + 2] - 2 * 'a') / 2 + 'a';
            }

        }
//        printf("i = %d s = %s\n",i,s);

    }
    puts(s);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

char rep(char c1,char c2)
{
    for(char chr='a';chr<='z';chr++)
    {
        if(chr!=c1&&chr!=c2)return chr;
    }
}

int main()
{
    string s;
    cin>>s;

    for(int x=1;x<s.size();x++)
    {
        if(s[x]==s[x-1])
        {
            s[x]=rep(s[x+1],s[x-1]);
        }
    }

    cout<<s<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool check(string s)
{
    int c=0;
    for(int x=1;x<s.size();x++)
    {
        if(s[x]==s[x-1])c++;
    }
    if(c==0)return false;
    else return true;
}

string sp(string s)
{
    for(int x=s.size()-2;x>=0;x--)
    {
            if(s[x]==s[x-1])
            {
                for(int y=s.size()-1;y>=0;y--)
                {
                    if(s[x-1]!=s[y]){
                            s[x-1]=s[y];
                            break;
                    }
                }
            }
    }

    return s;
}

int main()
{
    string s;
    cin>>s;
    while(check(s))
    {
        //cout<<check(s)<<endl;
        //cout<<sp(s)<<endl;
        s=sp(s);
    }

    cout<<s<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

char rep(char c1,char c2)
{
    for(char ch='a';ch<='z';ch++)
    {
        if(c1!=ch&&c2!=0)return ch;
    }
}

int main()
{
    string s;
    cin>>s;

    for(int x=1;x<s.size();x++)
    {
        if(s[x]==s[x-1])
        {
            s[x]=rep(s[x+1],s[x-1]);
        }
    }

    cout<<s<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

/**bool check(string s)
{
    int c=0;
    for(int x=1;x<s.size();x++)
    {
        if(s[x]==s[x-1])c++;
    }
    if(c==0)return false;
    else return true;
}**/

string sp(string s)
{
    for(int x=s.size()-2;x>=0;x--)
    {
            if(s[x]==s[x-1])
            {
                for(int y=s.size()-1;y>=0;y--)
                {
                    if(s[x-1]!=s[y]){
                            s[x-1]=s[y];
                            break;
                    }
                }
            }
    }

    return s;
}

int main()
{
    string s;
    cin>>s;

    s=sp(s);

    cout<<s<<endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

bool check(string s)
{
    int c=0;
    for(int x=1;x<s.size();x++)
    {
        if(s[x]==s[x-1])c++;
    }
    if(c==0)return false;
    else return true;
}

string sp(string s)
{
    for(int x=0;x<s.size()-1;x++)
    {
            if(s[x]==s[x+1])
            {
                for(int y=0;y<s.size();y++)
                {
                    if(s[x+1]!=s[y]){
                            s[x+1]=s[y];
                            break;
                    }
                }
            }
    }

    return s;
}

int main()
{
    string s;
    cin>>s;
    while(check(s))
    {
        //cout<<check(s)<<endl;
        //cout<<sp(s)<<endl;
        s=sp(s);
    }

    cout<<s<<endl;

    return 0;
}


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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

bool isachar(char c, int offset){
  if((c - 'a' + offset) <= 26)
    return true;
  return false;
}

int main(){
  string s;
  cin >> s;
  int length = sz(s);
  for(int i=0; i<length-1; i++){
    if(s[i] == s[i+1]){
      if(i+2 < length){
	if(s[i+1] == s[i+2]){
	  if(isachar(s[i+1], 1))
	    s[i+1] = (s[i+1] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+1] - 'a' - 1) + 'a';
	}
	else {
	  if(isachar(s[i+2], 1))
	    s[i+1] = (s[i+2] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+2] - 'a' - 1) + 'a';
	}
      }
      s[i+1] = isachar(s[i+1], 1) ? (s[i+1] - 'a' + 1) + 'a' : (s[i+1] - 'a' - 1) + 'a';
      i++;
    }
  }
  cout << s << endl;
  return 0;
}


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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

bool isachar(char c, int offset){
  return ((c - 'a' + offset) <= 26);
}

char construct(char c1, char c2){
  char temp = ((c1 - 'a' + 1) % 26) + 'a';
  //  cout << c1 << " " << c2 << " " << temp << endl;
  if(c2 != temp)
    return temp;
  else
    return (((c1 - 'a' + 2) % 26) + 'a');
}

int main(){
  string s;
  cin >> s;
  int length = sz(s);
  for(int i=0; i<length-1; i++){
    if(s[i] == s[i+1]){
      if(i+2 < length){
	if(s[i+1] == s[i+2]){
	  s[i+1] = construct(s[i+2], s[i+2]);
	}
	else {
	  s[i+1] = construct(s[i+2], s[i]);
	}
      }
      else
	s[i+1] = construct(s[i+1], s[i]);
      i++;
    }
  }
  cout << s << endl;
  return 0;
}


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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

bool isachar(char c, int offset){
  return ((c - 'a' + offset) <= 26);
}

int main(){
  string s;
  cin >> s;
  int length = sz(s);
  for(int i=0; i<length-1; i++){
    if(s[i] == s[i+1]){
      if(i+2 < length){
	if(s[i+1] == s[i+2]){
	  if(isachar(s[i+1], 1))
	    s[i+1] = (s[i+1] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+1] - 'a' - 1) + 'a';
	}
	else {
	  if(isachar(s[i+2], 1))
	    s[i+1] = (s[i+2] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+2] - 'a' - 1) + 'a';
	}
      }
      else
	s[i+1] = isachar(s[i+1], 1) ? (s[i+1] - 'a' + 1) + 'a' : (s[i+1] - 'a' - 1) + 'a';
      i++;
    }
  }
  cout << s << endl;
  return 0;
}


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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

bool isachar(char c, int offset){
  if((c - 'a' + offset) <= 26)
    return true;
  return false;
}

int main(){
  string s;
  cin >> s;
  int length = sz(s);
  for(int i=0; i<length-2; i++){
    if(s[i] == s[i+1]){
      if(s[i+1] == s[i+2]){
	if(isachar(s[i+1], 1))
	  s[i+1] = (s[i+1] - 'a' + 1) + 'a';
	else
	  s[i+1] = (s[i+1] - 'a' - 1) + 'a';
      }
      else {
	if(isachar(s[i+2], 1))
	  s[i+1] = (s[i+2] - 'a' + 1) + 'a';
	else
	  s[i+1] = (s[i+2] - 'a' - 1) + 'a';
      }
      i++;
    }
  }
  cout << s << endl;
  return 0;
}


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

#define ll long long
#define fr(i, n) for(int i=0;i<n;i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresetn(container, element) (find(all(container)), element) != container.end())
#define sz(a) int((a).size())

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;

bool isachar(char c, int offset){
  if((c - 'a' + offset) < 26)
    return true;
  return false;
}

int main(){
  string s;
  cin >> s;
  int length = sz(s);
  for(int i=0; i<length-1; i++){
    if(s[i] == s[i+1]){
      if(i+2 < length){
	if(s[i+1] == s[i+2]){
	  if(isachar(s[i+1], 1))
	    s[i+1] = (s[i+1] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+1] - 'a' - 1) + 'a';
	}
	else {
	  if(isachar(s[i+2], 1))
	    s[i+1] = (s[i+2] - 'a' + 1) + 'a';
	  else
	    s[i+1] = (s[i+2] - 'a' - 1) + 'a';
	}
      }
      s[i+1] = isachar(s[i+1], 1) ? (s[i+1] - 'a' + 1) + 'a' : (s[i+1] - 'a' - 1) + 'a';
      i++;
    }
  }
  cout << s << endl;
  return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='x';
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='u';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='i';
            }
        }
    }
    cout<<s;
    return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;
    int t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='a';
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='b';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='c';
            }
        }
    }
    cout<<s;
    return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='x';
                if(s[i+1]==s[i+2])
            {
                s[i+1]='i';
            }
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='u';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='i';
            }
        }
    }
    cout<<s;
    return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='q';
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='h';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='s';
            }
        }
    }
    cout<<s;
    return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;
    int t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='z';
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='q';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='w';
            }
        }
    }
    cout<<s;
    return 0;
}


///Chefer

#include <bits/stdc++.h>
#define int long long int

using namespace std;

main()
{
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++)
    {
        if(s[i+1]==s[i])
        {
            s[i+1]='x';
        }
        if(s[i+1]==s[i])
        {
            s[i+1]='u';
            if(s[i+1]==s[i+2])
            {
                s[i+1]='i';
            }
        }
        if(s[i+1]==s[i+2])
        {
            s[i+1]='i';
        }
    }
    cout<<s;
    return 0;
}


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

int main()
{
    char s[200036];
    cin>>s;
    int n=strlen(s);
    for(int i=1;i<n;i++)
    {
        if(s[i-1]==s[i]&&s[i]==s[i+1])
        {
            int l=((s[i]-'a')+1)%26;
            s[i]=(char)(l+'a');
        }
        else if(s[i-1]==s[i])
        {
            int l=((s[i]-'a')+1)%26;
            char temp=(char)(l+'a');
            if(i<n-1&&temp==s[i+1])
            {
                s[i-1]=temp;
            }
            else
                s[i]=temp;
        }

    }
    cout<<s<<endl;
    /*char c;
    cin>>c;
    int l=((c-'a')+1)%26;
    cout<<(char)(l+'a')<<endl;*/
    return 0;
}


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

int main()
{
    char s[100000];
    cin>>s;
    int n=strlen(s);
    for(int i=1;i<n;i++)
    {
        if(s[i-1]==s[i]&&s[i]==s[i+1])
        {
            int l=((s[i]-'a')+1)%26;
            s[i]=(char)(l+'a');
        }
        else if(s[i-1]==s[i])
        {
            int l=((s[i]-'a')+1)%26;
            char temp=(char)(l+'a');
            if(temp==s[i+1])
            {
                s[i-1]=temp;
            }
            else
                s[i]=temp;
        }
    }
    cout<<s<<endl;
    /*char c;
    cin>>c;
    int l=((c-'a')+1)%26;
    cout<<(char)(l+'a')<<endl;*/
    return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n-1;i++)
    {
        if(s[i]==s[i+1])
        {
            s[i+1]=((s[i]+1)%26)+'a';
        }
    }
    cout<<s<<endl;
    return 0;
}


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

int main()
{
    char s[200006];
    cin>>s;
    int n=strlen(s);
    for(int i=1;i<n;i++)
    {
        if(s[i-1]==s[i]&&s[i]==s[i+1])
        {
            int l=((s[i]-'a')+1)%26;
            s[i]=(char)(l+'a');
        }
        else if(s[i-1]==s[i])
        {
            int l=((s[i]-'a')+1)%26;
            char temp=(char)(l+'a');
            if(temp==s[i+1])
            {
                s[i-1]=temp;
            }
            else
                s[i]=temp;
        }
    }
    cout<<s<<endl;
    /*char c;
    cin>>c;
    int l=((c-'a')+1)%26;
    cout<<(char)(l+'a')<<endl;*/
    return 0;
}


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

int main()
{
    char s[200036];
    cin>>s;
    int n=strlen(s);
    for(int i=1;i<n;i++)
    {
        if(s[i-1]==s[i]&&s[i]==s[i+1])
        {
            int l=((s[i]-'a')+1)%26;
            s[i]=(char)(l+'a');
        }
        else if(s[i-1]==s[i])
        {
            int l=((s[i]-'a')+1)%26;
            char temp=(char)(l+'a');
            if(temp==s[i+1])
            {
                s[i-1]=temp;
            }
            else
                s[i]=temp;
        }

    }
    cout<<s<<endl;
    /*char c;
    cin>>c;
    int l=((c-'a')+1)%26;
    cout<<(char)(l+'a')<<endl;*/
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>

using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair <string, int> psi;
typedef pair <int, string> pis;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef set<int> si;

string s;

void solve(){
	char prev = s[0];
	char cur;
	char next;
	if (s.length() > 2){
 	for (int i = 1 ;i  < s.length() - 1; i++){
 		if (prev == s[i]){
 			if (s[i] < 122){
 			 	if (s[i] + 1 != s[i+1]) s[i]++;
 			 	else{
 			 		if (s[i  + 1] < 122) s[i]++;
 			 		else s[i] = 97;
 			 	}
 			}
 			else{
 				if (s[i + 1] != 97) s[i]  = 97;
 				else s[i] = 98;
 			}
 		}
 		prev = s[i];
 	}
 	}
 	else{
 	 	if (s.length() == 2){
 	 	 	if (s[0] == s[1]){
 	 	 	 	if (s[0] < 122){
                 	if (s[0] + 1 != s[1]) s[0]++;
                 	else{
                 	 	if (s[1] < 122) s[0]++;
                 	 	else s[0]=97;
                 	}
                }
                else{
                 	if (s[1] != 97) s[0] = 97;
                 	else s[0] = 98;
                }
 	 	 	}
 	 	}
 	}
 	cout << s << endl;
}
void solve2(){
 	cout <<(int) s[0];
}

int main(){
    cin >> s;
    solve();
 	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string s;
int n;

void read(){
    cin >> s;
    n = (int) s.length();
}

char nextchar(char c){
 	if (c != 122) return c + 1;
 	return 'a';
}
void solve(){
	for (int i=0;i < n - 1; i++){
	  	if (s[i+1] == s[i]){
	  		if (i + 2 < n){
	  		 	s[i+1] = nextchar(s[i+2]);
	  		}
	  		else{
	  		 	s[i+1] = nextchar(s[i+1]);
	  		}
	  	}
	}
}
int main(){
	read();
	solve();
	cout << s;
 	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string s;
int n;

void read(){
    cin >> s;
    n = (int) s.length();
}

char nextchar(char c){
 	if (c != 122) return c + 1;
 	return 'a';
}
void solve(){
	for (int i=0;i < n - 1; i++){
	  	if (s[i+1] == s[i]){
	  		if (i + 2 < n){
	  			if (nextchar(s[i+1]) == s[i+2]) s[i+1] = nextchar(s[i+2]);
	  			else s[i+1] = nextchar(s[i+1]);
	  		}
	  		else{
	  		 	s[i+1] = nextchar(s[i+1]);
	  		}
	  	}
	}
}
int main(){
	read();
	solve();
	cout << s;
 	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>

using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair <string, int> psi;
typedef pair <int, string> pis;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef set<int> si;

string s;

void solve(){
	char prev = s[0];
	char cur;
	char next;
	if (s.length() > 2){
 	for (int i = 1 ;i  < s.length() - 1; i++){
 		if (prev == s[i]){
 			if (s[i] < 122){
 			 	if (s[i] + 1 != s[i+1]) s[i]++;
 			 	else{
 			 		if (s[i  + 1] < 122) s[i] = s[i+1] + 1;
 			 		else s[i] = 97;
 			 	}
 			}
 			else{
 				if (s[i + 1] != 97) s[i]  = 97;
 				else s[i] = 98;
 			}
 		}
 		prev = s[i];
 	}
 	}
 	else{
 	 	if (s.length() == 2){
 	 	 	if (s[0] == s[1]){
 	 	 	 	if (s[0] < 122){
                 	if (s[0] + 1 != s[1]) s[0]++;
                 	else{
                 	 	if (s[1] < 122) s[0] = s[1] + 1;
                 	 	else s[0]=97;
                 	}
                }
                else{
                 	if (s[1] != 97) s[0] = 97;
                 	else s[0] = 98;
                }
 	 	 	}
 	 	}
 	}
 	cout << s << endl;
}
void solve2(){
 	cout <<(int) s[0];
}

int main(){
    cin >> s;
    solve();
 	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>

using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair <string, int> psi;
typedef pair <int, string> pis;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef set<int> si;

string s;

void solve(){
	char prev = s[0];
	char cur;
	char next;
	if (s.length() > 2){
 	for (int i = 1 ;i  < s.length() - 1; i++){
 		if (prev == s[i]){
 			if (s[i] < 122){
 			 	if (s[i] + 1 != s[i+1]) s[i]++;
 			 	else{
 			 		if (s[i  + 1] < 122) s[i] = s[i+1] + 1;
 			 		else s[i] = 97;
 			 	}
 			}
 			else{
 				if (s[i + 1] != 97) s[i]  = 97;
 				else s[i] = 98;
 			}
 		}
		if (i + 1 < s.length()){
		 	if (s[i]  == s[i+1]){
		 	 	if (s[i] < 122){
                 	if (s[i] + 1 != s[i+1]) s[0]++;
                 	else{
                 	 	if (s[i+1] < 122) s[i] = s[i+1] + 1;
                 	 	else s[i]=97;
                 	}
                }
                else{
                 	if (s[i+1] != 97){
                 		if (s[i- 1] != 97) s[i] = 97;
                 		else s[i] = 98;
                 	}
                 	else{
                 	 	if (s[i - 1] != 98) s[i] = 98;
                 	 	else s[i] = 99;
                 	}
                }
		 	}
		}
 		prev = s[i];
 	}
 	}
 	else{
 	 	if (s.length() == 2){
 	 	 	if (s[0] == s[1]){
 	 	 	 	if (s[0] < 122){
                 	if (s[0] + 1 != s[1]) s[0]++;
                 	else{
                 	 	if (s[1] < 122) s[0] = s[1] + 1;
                 	 	else s[0]=97;
                 	}
                }
                else{
                 	if (s[1] != 97) s[0] = 97;
                 	else s[0] = 98;
                }
 	 	 	}
 	 	}
 	}
 	cout << s << endl;
}
void solve2(){
 	cout <<(int) s[0];
}

int main(){
    cin >> s;
    solve();
 	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string s;
int n;

void read(){
    cin >> s;
    n = (int) s.length();
}

char nextch(char c){
 	if (c != 122) return c + 1;
 	return 'a';
}
void solve(){
	for (int i = 0;i < n- 1; i++){
	  	if (s[i + 1] == s[i]){
	  	 	s[i + 1] = nextch(s[i+  1]);
		}
 	}
}
int main(){
	read();
	solve();
	cout << s;
 	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <cstring>

using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
typedef pair <string, int> psi;
typedef pair <int, string> pis;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef set<int> si;

string s;

void solve(){
	char prev = s[0];
	char cur;
	char next;
 	for (int i = 1 ;i  < s.length() - 1; i++){
 		if (prev == s[i]){
 			if (s[i] + 1  != s[i+1]){
 				s[i]+=1;
 		 	}
 		 	else{
 		 	 	s[i]+=2;
 		 	}
 		}
 		prev = s[i];
 	}
 	cout << s << endl;
}

int main(){
    cin >> s;
    solve();
 	return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i=0; i<s.length()-1; i++)
    {
        if(s[i] == s[i+1] && s[i]!=s[i+2])
            s[i+1] = s[i+2]+1 <= 'z' ?  s[i+2]+1:s[i]-1;
         else if(s[i] == s[i+1] && s[i]==s[i+2])
            s[i+1] = s[i+2]+1 <= 'z' ? (s[i+2]+1):(s[i+2]-2);
        else if(s[i]==s[i+1] && s.length() > 2)
            s[i+1] = s[i+1]+1;
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    s += ' ';
    for(int i=1; i<s.length(); i++)
    {
        if(s[i] == s[i-1])
        {
            if(s[i] != 'a' && s[i+1] != 'a')
                s[i] = 'a';
            else if(s[i]!= 'z' && s[i+1] != 'z')
                s[i] = 'z';
            else
                s[i] = 'c';
        }
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i=1; i<s.length(); i++)
    {
        if(s[i] == s[i-1])
        {
            if(s[i] != 'a')
                s[i] = 'a';
            else if(s[i]!= 'b')
                s[i] = 'b';
        }
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i=1; i<s.length()-1; i++)
    {
        if(s[i] == s[i-1])
        {
            if(s[i] != 'a' && s[i+1] != 'a')
                s[i] = 'a';
            else if(s[i]!= 'z' && s[i+1]!='z')
                s[i] = 'z';
        }
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    s += ' ';
    for(int i=1; i<s.length(); i++)
    {
        if(s[i] == s[i-1])
        {
            if(s[i] != 'a' && s[i+1] != 'a')
                s[i] = 'a';
            else if(s[i]!= 'z' && s[i+1] != 'z')
                s[i] = 'z';
//            else
//                s[i] = 'c';
        }
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i=1; i<s.length(); i++)
    {
        if(s[i] == s[i-1])
        {
            if(s[i] != 'a' && s[i+1] != 'a')
                s[i] = 'a';
            else if(s[i]!= 'z' && s[i+1]!='z')
                s[i] = 'z';
        }
    }
    cout << s;
    return 0;
}


#include <bits/stdc++.h>
#include <sstream>
#define ll long long
#define pi 3.1415926535897
#define eps 0.0000000001
#define F first
#define S second
#define MAX 1000000000000
#define MIN 1e-7
#define mod 1000000007
using namespace std;
const int Max = 10055;

int main()
{
    string s;
    cin >> s;
    int res = 0;
    for(int i=0; i<s.length()-1; i++)
    {
        if(s[i]==s[i+1] && s[i] == s[i+2])
            s[i+1] = s[i+2]+1 < 'z' ? s[i+2]+1 : s[i]-1;
        else if(s[i] == s[i+1] && i > 0)
            if((s[i+1] + 1 != s[i+1]) && (s[i-1] != s[i+1]+1) )
                s[i+1] = s[i+1]+1;
            else
                s[i+1] = s[i+1]+5;
        else if(s[i] == s[i+1] && i==0)
            s[i] = s[i+1]+1;

    }
    cout << s;
    return 0;
}


//2016-05-25 19:40:20.684000
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define beyond(x, y) (x<0 || y<0 || x>=N || y>=M)
#define sq(x) ((x)*(x))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3fLL
#define eps 1e-7

typedef long long INT;
typedef long double DO;
typedef pair<int, int> pii;

template<class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template<class T> inline void smax(T &a, T b) {if (a<b) a=b;}

int dx[]={1, 0, -1, 0, 1, 1, -1, -1};
int dy[]={0, 1, 0, -1, -1, 1, 1, -1};
int qf, qb, q[1111111];

char s[1111111];

int main() {
	int T, N, i, j, M, k;
	scanf("%s", s);
	int len=strlen(s);
	for (i=1; i<len; i++) {
		if (s[i]==s[i-1]) {
			for (k=0; k<26; k++) {
				if (i<len-1 && s[i]!=k+'a' && s[i+1]!=k+'a') break;
				else if (i==len-1 && s[i]!='a'+k) break;
			}
			s[i]=k+'a';
		}
	}
	printf("%s\n", s);
	return 0;
}


//2016-05-25 19:41:33.708000
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define NN 1111111
char s[NN];
int main() {

	int len, i, j;
	while(scanf("%s", s)==1) {
		len=strlen(s);
		for(i=1; i<len; i++) {
			if(s[i]==s[i-1]) {
				for(j=0; j<26; j++) if(j+'a'!=s[i-1] && j+'a'!=s[i+1]) break;
				s[i]=j+'a';
			}
		}
		puts(s);
	}

	return 0;
}


//2016-05-25 19:47:12.077000
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <memory.h>
#define NN 200010

using namespace std;

char str[NN];

int main (){

	scanf("%s",str);
	int N=strlen(str), i,j,k;
	char c;

	for(i=0; i<N; i++){
		k=i;
		while(str[k]==str[k+1]){
			k++;
		}

		for(j=0; j<26; j++){
			if(str[i]-'a'!=j && str[k+1]-'a'!=j) break;
		}
		c='a'+j;

		for(j=i+1; j<=k; j+=2){
			str[j]=c;
		}

		i=k;
	}

	printf("%s\n",str);

	return 0;
}


//2016-05-25 19:34:36.939000
#include <algorithm>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long INT;
#define NN 1000010
char s[NN],t[NN];
int main(){
//	freopen("c.in","r",stdin);
	int n,i,j;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++){
		if(!i){t[i]=s[i];continue;}
		if(t[i-1]==s[i]){
			if(i==(n-1)) s[i]=t[i-1]+1;
			for(j=1;j<26;j++){
				if(s[i]+j!=s[i+1]) break;
			}
			t[i]=t[i-1]+j;
		}
		else{
			t[i]=s[i];
		}
	}
	for(i=0;i<n;i++) printf("%c",t[i]);
}


//2016-05-25 19:33:29.206000
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <memory.h>
#define NN 200010

using namespace std;

char str[NN];

int main (){

	scanf("%s",str);
	int N=strlen(str), i,j,k;
	char c;

	for(i=0; i<N; i++){
		k=i;
		while(str[k]==str[k+1]){
			k++;
		}
		if(k==i) continue;
		for(j=0; j<26; j++){
			if(str[i]-'a'!=j && str[k+1]-'a'!=j) break;
		}
		c='a'+j;

		for(j=i+1; j<=k; j++){
			str[j]=c;
		}
	}

	printf("%s\n",str);

	return 0;
}


//2016-05-25 19:45:02.136000
#include <algorithm>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;

#define NN 210000

typedef pair<int, int> pii;
typedef long long INT;

char str[NN];

int main() {
	scanf("%s", str);

	int len=strlen(str);

	for (int i=1; i<len; i++) {
		if (str[i]==str[i-1]) {
			for (str[i]='a'; str[i]==str[i-1] || str[i]==str[i+1]; str[i]++);
		}
	}

	puts(str);

	return 0;
}


//2016-05-25 19:32:47.396000
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <map>

using namespace std;

#define beyond(x, y) (x<0 || y<0 || x>=N || y>=M)
#define sq(x) ((x)*(x))
#define x first
#define y second

typedef pair<int, int> pii;
typedef long long INT;
template <class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template <class T> inline void smax(T &a, T b) {if (a<b) a=b;}
int dx[]={1, 0, -1, 0, 1, 1, -1, -1};
int dy[]={0, 1, 0, -1, -1, 1, 1, -1};
int qf, qb, q[1111111];
char s[1111111];
int main() {

	int len, i,k;
	while (scanf("%s", s) ==1) {
		len=strlen(s);
		for (i=1; i<len; i++) {
			if (s[i]==s[i-1]) {
				for (k=0; k<26; k++) {
					if (k!=(s[i]-'a') && k!=(s[i+1]-'a')) {
						s[i]=k+'a';
					}
				}
			}
		}
		puts(s);
	}

	return 0;
}


//2016-05-25 19:51:31.367000
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <map>

using namespace std;

#define beyond(x, y) (x<0 || y<0 || x>=N || y>=M)
#define sq(x) ((x)*(x))
#define x first
#define y second

typedef pair<int, int> pii;
typedef long long INT;
template <class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template <class T> inline void smax(T &a, T b) {if (a<b) a=b;}
int dx[]={1, 0, -1, 0, 1, 1, -1, -1};
int dy[]={0, 1, 0, -1, -1, 1, 1, -1};
int qf, qb, q[1111111];
char s[1111111];

int main() {

	int len, i,k;
	while (scanf("%s", s) ==1) {
		len=strlen(s);
		s[len]=0;
		for (i=1; i<len; i++) {
			if (s[i]==s[i-1]) {
				for (k=0; k<26; k++) {
					if (k!=(s[i-1]-'a') && k!=(s[i+1]-'a')) {
						s[i]=k+'a';
					}
				}
			}
		}
		puts(s);
	}

	return 0;
}


//2016-05-25 19:31:48.554000
#include <algorithm>
#include <cstdio>
#include <memory.h>
#include <set>
#include <queue>
#include <string.h>
#include <vector>
#include <cmath>
#include <bitset>
#include <map>

using namespace std;

#define NN 200010
#define rep(i, a, b) for (int i = (a); i < (b); i ++)
#define clr(a, b) memset(a, b, sizeof(a))
#define eps 1e-10
#define inf 1000000000

typedef long long INT;
typedef pair<int, int> pii;
typedef pair<pii, int> pi3;

char str[NN];
char s[NN];

int main() {

	int N;
	char c;

	scanf("%s", str);
	N = strlen(str);
	s[0] = str[0];
	rep(i, 1, N) {
		if (str[i] != s[i - 1]) {
			s[i] = str[i] ;
			continue ;
		}
		rep(j, 0, 26) {
			c = 'a' + j;
			if (c == s[i - 1]) continue ;
			if (i < N - 1 && c == str[i + 1]) continue ;
			s[i] = c;
			break ;
		}
	}
	s[N] = 0;
	printf("%s\n", s);

	return 0;
}


//2016-05-25 20:10:08.559000
#include <algorithm>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long INT;
#define NN 1000010
char s[NN],t[NN];
int main(){
//	freopen("c.in","r",stdin);
	int n,i,j;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++){
		if(!i){t[i]=s[i];continue;}
		if(t[i-1]==s[i]){
			if(i==(n-1)) s[i]=t[i-1]+(t[i-1]-'a'+1)%26;
			for(j=1;j<26;j++){
				if('a'+(s[i]-'a'+j)%26!=s[i+1]) break;
			}
			t[i]='a'+(t[i-1]-'a'+j)%26;
		}
		else{
			t[i]=s[i];
		}
	}
	for(i=0;i<n;i++) printf("%c",t[i]);
}


//2016-05-25 19:34:04.956000
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <memory.h>
#define NN 200010

using namespace std;

char str[NN];

int main (){

	scanf("%s",str);
	int N=strlen(str), i,j,k;
	char c;

	for(i=0; i<N; i++){
		k=i;
		while(str[k]==str[k+1]){
			k++;
		}

		for(j=0; j<26; j++){
			if(str[i]-'a'!=j && str[k+1]-'a'!=j) break;
		}
		c='a'+j;

		for(j=i+1; j<=k; j++){
			str[j]=c;
		}

		i=k;
	}

	printf("%s\n",str);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,j,k,l,m,dp[200001];
char c;
cin>>s;
l=s.length();
for(k=1;k<l;k++)
if(s[k-1]==s[k])
{for(i=97;i<=122;i++)
if(k>0&&i!=s[k-1]&&i!=s[k+1])
{s[k]=char(i);break;}i++;}
cout<<s<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,j,k,l,m,dp[200001];
char c;
cin>>s;
l=s.length();
for(i=0;i<l;i++)
if(s[i-1]==s[i])
{dp[i]=1;i++;}
for(k=1;k<l;k++)
{
if(dp[k]==1)
{
for(i=97;i<=102;i++)
{
// c=(char)i;
if(k>0&&i!=s[k-1]&&i!=s[k+1])//&&i!=s[k+1])
{
s[k]=char(i);break;}
}
}
}
cout<<s<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,j,k,l,m,dp[200001];
char c;
cin>>s;
l=s.length();
for(i=0;i<l;i++)
if(s[i-1]==s[i])
{dp[i]=1;i++;}
for(k=1;k<l;k++)
if(dp[k]==1)
for(i=97;i<=122;i++)
if(k>0&&i!=s[k-1]&&i!=s[k+1])
{s[k]=char(i);break;}
cout<<s<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,j,k,l,m,dp[200001];
char c;
cin>>s;
l=s.length();
for(i=0;i<=l;i++)
if(s[i-1]==s[i])
{dp[i]=1;i++;}
for(k=1;k<l;k++)
//if(dp[k]==1)
if(s[k-1]==s[k])
{for(i=97;i<=122;i++)
if(k>0&&i!=s[k-1]&&i!=s[k+1])
{s[k]=char(i);break;}i++;}
cout<<s<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
int i,j,k,l,m,dp[200001];
char c;
cin>>s;
l=s.length();
for(i=0;i<=l;i++)
if(s[i-1]==s[i])
{dp[i]=1;i++;}
for(k=1;k<l;k++)
if(dp[k]==1)
for(i=97;i<=122;i++)
if(k>0&&i!=s[k-1]&&i!=s[k+1])
{s[k]=char(i);break;}
cout<<s<<endl;
return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int n;
char s[200010],c[200010];
int main() {
	scanf("%s",s + 1);
	n = strlen(s + 1);int j;
	s[0] = ' ',s[n + 1] = ' ';
	for(int i = 1;i <= n;i ++) c[i] = s[i];
	for(int i = 1;i <= n;i = j)
	{
		j = i;
		while(s[j] == s[i] && j <= n) j ++;
		if((j - i) % 2 == 1)
		{
			for(int k = i + 1;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
		else
		{
			if(s[i - 1] == 'a')
				{
					if(s[i] == 'b') c[i] = 'c';
					else c[i] = 'b';
				}
			else
			{
				if(s[i] == 'a')
					{if(s[i - 1] != 'b') c[i] = 'b';}
				else c[i] = 'a';
 			}
			for(int k = i + 2;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
	}
	for(int i = 1;i <= n;i ++) cout<<c[i];
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int n;
char s[200010],c[200010];
int main() {
	scanf("%s",s + 1);
	n = strlen(s + 1);int j;
	s[0] = ' ',s[n + 1] = ' ';
	for(int i = 1;i <= n;i ++) c[i] = s[i];
	for(int i = 1;i <= n;i = j)
	{
		j = i;
		while(s[j] == s[i] && j <= n) j ++;
		if((j - i) % 2 == 1)
		{
			for(int k = i + 1;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
		else
		{
			if(s[i - 1] == 'a')
			{
				if(s[i] == 'b') c[i] = 'c';
				else c[i] = 'b';
			}
			else
			{
				if(s[i] == 'a')
					{
						if(s[i - 1] != 'b') c[i] = 'b';
						else c[i] = 'c';
					}
				else c[i] = 'a';
 			}
			for(int k = i + 2;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
	}
	for(int i = 1;i <= n;i ++) cout<<c[i];
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int n;
char s[200010],c[200010];
int main() {
	//freopen("lx.in","r",stdin);
	scanf("%s",s + 1);
	n = strlen(s + 1);int j;
	s[0] = ' ',s[n + 1] = ' ';
	for(int i = 1;i <= n;i ++) c[i] = s[i];
	for(int i = 1;i <= n;i = j)
	{
		j = i;
		while(s[j] == s[i] && j <= n) j ++;
		if((j - i) % 2 == 1)
		{
			for(int k = i + 1;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
		else
		{
			if(s[i - 1] == 'a')
				{
					if(s[i] == 'b') c[i] = 'c';
					else c[i] = 'b';
				}
			else
			{
				if(s[i] == 'a')
					if(s[i - 1] != 'b') c[i] = 'b';
				else c[i] = 'a';
 			}
			for(int k = i + 2;k < j;k += 2)
			{
				if(s[k] == 'a') c[k] = 'b';
				else c[k] = 'a';
			}
		}
	}
	for(int i = 1;i <= n;i ++) cout<<c[i];
}


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

int main() {
	// your code goes here
	int i,n;
	char s[1000000];
	cin>>s;
	n=strlen(s);
	for(i=1;i<n-1;i++)
	{
		if(a[i]==a[i-1] && a[i]==a[i+1])
		{
			if(a[i]!='a')
			a[i]='a'-1;
			else
			a[i]='b';
		}
	}
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			if(a[i-1]!='a')
			a[i-1]='a'-1;
			else
			a[i-1]='b';
		}
	}
	cout<<s;
	return 0;
}


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

int main() {
	// your code goes here
	char s[1000000],i,n;
	cin>>s;
	n=strlen(s);
	for(i=1;i<n;i++)
	{
		if(s[i]==s[i-1])
		{
			if(s[i]==s[i+1] && i<n)
			{
				if(s[i]!='a')
				s[i]='a';
				else
				s[i]='b';
			}
			else
			{
				if(i>=2)
				{
				if(s[i]!='a'&& s[i-2]!='a')
				s[i-1]='a';
				else
				s[i-1]='b';
				}
				else
				{
					if(s[i]!='a')
				s[i-1]='a';
				else
				s[i-1]='b';
				}
			}
		}
	}
	cout<<s<<endl;
	return 0;
}


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

int main() {
	// your code goes here
	int i,n;
	char a[1000000];
	cin>>a;
	n=strlen(a);
	for(i=1;i<n-1;i++)
	{
		if(a[i]==a[i-1] && a[i]==a[i+1])
		{
			if(a[i]!='a')
			a[i]='a'-1;
			else
			a[i]='b';
		}
	}
	for(i=1;i<n;i++)
	{
		if(a[i]==a[i-1])
		{
			if(a[i-1]!='a')
			a[i-1]='a'-1;
			else
			a[i-1]='b';
		}
	}
	cout<<a;
	return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;
int a[110], b[110];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, s, ans1, ans2;
	while(cin >> n >> s) {
		int find = 1;
		for(int i = 0; i < n; i++)
			cin >> a[i] >> b[i];
		for(int i = 1; i < n; i++) {
			int H = a[i]*60 + b[i] - a[i-1]*60 - b[i - 1];
			if(H >= 2*s + 2) {
				find = 0;
				ans2 = s + 1 + b[i - 1];  // hours
				ans1 = a[i - 1];
				if(ans2 >= 60) {
					ans2 = ans2 - 60;
					ans1 = ans1 + 1;
				}
				break;
			}
		}
		if(find == 1) {
			ans2 = b[n - 1] + 1 + s;
			ans1 = a[n - 1];
			if(ans2 >= 60) {
				if(ans2 >= 120) {
					ans2 = ans2 - 60;
					ans1 = ans1 + 1;
				}
				ans2 = ans2 - 60;
				ans1 = ans1 + 1;
			}
		}
		if(a[0]*60 + b[0] >= s + 1) {
			ans1 = 0;
			ans2 = 0;
		}
		if(ans2 == 60) {
			ans1 = ans1 + 1;
			ans2 = 0;
		}
		cout << ans1 << " " << ans2 << endl;
	}
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;
int a[110], b[110];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, s, ans1, ans2;
	while(cin >> n >> s) {
		int find = 1;
		for(int i = 0; i < n; i++)
			cin >> a[i] >> b[i];
		for(int i = 1; i < n; i++) {
			int H = a[i]*60 + b[i] - a[i-1]*60 - b[i - 1];
			if(H >= 2*s + 2) {
				find = 0;
				ans2 = s + 1 + b[i - 1];  // hours
				ans1 = a[i - 1];
				if(ans2 >= 60) {
					ans2 = ans2 - 60;
					ans1 = ans1 + 1;
				}
				break;
			}
		}
		if(find == 1) {
			ans2 = b[n - 1] + 1 + s;
			ans1 = a[n - 1];
			if(ans2 >= 60) {
				if(ans2 >= 120) {
					ans2 = ans2 - 60;
					ans1 = ans1 + 1;
				}
				ans2 = ans2 - 60;
				ans1 = ans1 + 1;
			}
		}
		if(a[0]*60 + b[0] >= s + 1) {
			ans1 = 0;
			ans2 = 0;
		}
		cout << ans1 << " " << ans2 << endl;
	}
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;
int a[110], b[110];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, s, ans1, ans2;
	while(cin >> n >> s) {
		int find = 1;
		for(int i = 0; i < n; i++)
			cin >> a[i] >> b[i];
		for(int i = 1; i < n; i++) {
			int H = a[i]*60 + b[i] - a[i-1]*60 - b[i - 1];
			if(H >= 2*s + 2) {
				find = 0;
				ans2 = s + 1 + b[i - 1];  // hours
				ans1 = a[i - 1];
				if(ans2 >= 60) {
					ans2 = ans2 - 60;
					ans1 = ans1 + 1;
				}
				break;
			}
		}
		if(find == 1) {
			ans2 = b[n - 1] + 1 + s;
			ans1 = a[n - 1];
			if(ans2 >= 60) {
				ans2 = ans2 - 60;
				ans1 = ans1 + 1;
			}
		}
		if(a[0]*60 + b[0] >= s + 1) {
			ans1 = 0;
			ans2 = 0;
		}
		cout << ans1 << " " << ans2 << endl;
	}
}


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

int a[N],b[N];
int xiaoyu(int x1,int y1,int x2,int y2)
{
	while (x1<x2) y1-=60,x1++;
	while (x1>x2) y1+=60,x1--;
	return y1<y2;
}
int main()
{
	int n,k,lasth=0,lastm=0;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d%d",a+i,b+i);
	for (int i=1;i<=n;i++)
	{
		int hour=a[i],minn=b[i];
		minn-=k;
		while (minn<=0) hour--,minn+=60;
		if (xiaoyu(lasth,lastm,hour,minn) )
		{
			printf("%d %d",lasth,lastm);
			return 0;
		}
		hour=a[i],minn=b[i];
		minn+=k;
		while (minn>59) minn-=60,hour++;
		lasth=hour,lastm=minn+1;
		while (lastm<=0) lastm+=60,lasth--;
	}
	printf("%d %d",lasth,lastm);
}


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

int a[N],b[N];
int xiaoyu(int x1,int y1,int x2,int y2)
{
	while (x1<x2) y1-=60,x1++;
	while (x1>x2) y1+=60,x1--;
	return y1<y2;
}
int main()
{
	int n,k,lasth=0,lastm=0;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d%d",a+i,b+i);
	for (int i=1;i<=n;i++)
	{
		int hour=a[i],minn=b[i];
		minn-=k;
		while (minn<0) hour--,minn+=60;
		if (xiaoyu(lasth,lastm,hour,minn) )
		{
			printf("%d %d",lasth,lastm);
			return 0;
		}
		hour=a[i],minn=b[i];
		minn+=k;
		while (minn>59) minn-=60,hour++;
		lasth=hour,lastm=minn+1;
	}
	printf("%d %d",lasth,lastm);
}


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

int a[N],b[N];
int xiaoyu(int x1,int y1,int x2,int y2)
{
	while (x1<x2) y1-=60,x1++;
	while (x1>x2) y1+=60,x1--;
	return y1<y2;
}
int main()
{
	int n,k,lasth=0,lastm=0;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d%d",a+i,b+i);
	for (int i=1;i<=n;i++)
	{
		int hour=a[i],minn=b[i];
		minn-=k;
		while (minn<0) hour--,minn+=60;
		if (xiaoyu(lasth,lastm,hour,minn) )
		{
			printf("%d %d",lasth,lastm);
			return 0;
		}
		hour=a[i],minn=b[i];
		minn+=k;
		while (minn>=59) minn-=60,hour++;
		lasth=hour,lastm=minn+1;
	}
	printf("%d %d",lasth,lastm);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		else if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	if(vis1>=25) printf("24 59\n");
	else printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		else if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		else if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		else if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		else if(i==n&&ans==0){
			vis1=(h[i]+(m[i]+k+1)/60)%25;
			vis2=(m[i]+k+1)%60;
		}
	}
	printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		else if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		else if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	if(vis1>=25) printf("24 59\n");
	else printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-2-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		else if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		else if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	printf("%d %d\n",vis1,vis2);
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n,k,h[105],m[105],vis1,vis2;
bool ans;
int main(){
	scanf("%d%d",&n,&k);
	h[0]=0;
	m[0]=0;
	ans=0;
	for(int i=1;i<=n;i++) scanf("%d%d",&h[i],&m[i]);
	for(int i=1;i<=n;i++){
		if(i==1){
			if(h[i]*60+m[i]-1-k>=0){
				vis1=0;
				vis2=0;
				break;
			}
		}
		if(ans==0&&((h[i]*60+m[i]-1-(h[i-1]*60+m[i-1]+1))>=2*k)){
			vis1=h[i-1]+(m[i-1]+k+1)/60;
			vis2=(m[i-1]+k+1)%60;
			ans=1;
			break;
		}
		if(i==n&&ans==0){
			vis1=h[i]+(m[i]+k+1)/60;
			vis2=(m[i]+k+1)%60;
		}
	}
	if(vis1>=25) printf("24 59\n");
	else printf("%d %d\n",vis1,vis2);
}


#include <iostream>
#include <algorithm>

using namespace std;

long long n, s, ans;
long long t[100001];

int main(int argc, char ** argv)
{
	ios::sync_with_stdio(false);
	cin >> n >> s;
	ans = 0x7f7f7f7f;
	for (int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		t[i] = a * 60 + b;
		if (i > 1)
		{
			if (t[i] - t[i - 1] > s + s + 1)
				ans = min(ans, t[i - 1] + s + 1);
		}
		else
			if (t[i] >= s + 1)
				ans = 0;
	}
	if (ans == 0x7f7f7f7f)
		ans = t[n] + 1 + s;
	cout << ans / 60 << " " << ans % 60 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

long long n, s, ans;
long long t[100001];

int main(int argc, char ** argv)
{
	ios::sync_with_stdio(false);
	cin >> n >> s;
	ans = 0x7f7f7f7f;
	for (int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		t[i] = a * 60 + b;
		if (i > 1)
		{
			if (t[i] - t[i - 1] > s + s + 1)
				ans = min(ans, t[i - 1] + s + 1);
		}
		else
			if (t[i] > s + 1)
				ans = 0;
	}
	if (ans == 0x7f7f7f7f)
		ans = t[n] + 1 + s;
	cout << ans / 60 << " " << ans % 60 << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, s, ans;
int t[100001];

int main(int argc, char ** argv)
{
	ios::sync_with_stdio(false);
	cin >> n >> s;
	ans = 0x7f7f7f7f;
	for (int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		t[i] = a * 60 + b;
		if (i > 1)
		{
			if (t[i] - t[i - 1] > s + s + 1)
				ans = min(ans, t[i - 1] + s + 1);
		}
		else
			if (t[i] > s + 1)
				ans = 0;
	}
	if (ans == 0x7f7f7f7f)
		ans = t[n] + 1 + s;
	cout << ans / 60 << " " << ans % 60 << endl;
	return 0;
}


#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
    ll x=0;int ch=getchar(),f=1;
    while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
    if (ch=='-'){f=-1;ch=getchar();}
    while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}
int n,s,x,y,a[105];
int main(){
    n=read(),s=read();
    For(i,1,n){
        x=read(),y=read();
        a[i]=x*60+y;
    }
    if (a[1]>s) return printf("0 0"),0;
    a[n+1]=1000000000;
    For(i,2,n+1) if(a[i]-a[i-1]>2*s+1) return printf("%d %d",(a[i-1]+s+1)/60,(a[i-1]+s+1)%60),0;
}


#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
    ll x=0;int ch=getchar(),f=1;
    while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
    if (ch=='-'){f=-1;ch=getchar();}
    while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,sum,x,y,last_x,last_y;
int main(){
	n=read(),m=read();
	For(i,1,n){
		x=read(),y=read();
		sum=(x-last_x)*60-last_y+y;
		if (i==1){
			if (sum>m) return printf("0 0"),0;
		}
		else if (sum>m*2+1) return printf("%d %d",last_x+(last_y+m+1)/60,(last_y+m+1)%60),0;
		last_x=x,last_y=y;
	}
	printf("%d %d",last_x+(last_y+m+1)/60,(last_y+m+1)%60);
}


#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#define rg register
#define il inline
#define vd void
#define ll long long
#define For(i,x,y) for (rg int i=(x);i<=(y);i++)
#define Dow(i,x,y) for (rg int i=(x);i>=(y);i--)
#define cross(i,k) for (rg int i=first[k];i;i=last[i])
using namespace std;
il ll max(ll x,ll y){return x>y?x:y;}
il ll min(ll x,ll y){return x<y?x:y;}
il ll read(){
    ll x=0;int ch=getchar(),f=1;
    while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
    if (ch=='-'){f=-1;ch=getchar();}
    while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return x*f;
}
int n,m,sum,x,y,last_x,last_y;
int main(){
	n=read(),m=read();
	For(i,1,n){
		x=read(),y=read();
		if (y>last_y) sum=(x-last_x)*60+y-last_y;
			else sum=(x-last_x-1)*60+60-last_y+y;
		if (i==1){
			if (sum>m){
				printf("0 0");
				return 0;
			}
		}
		else if (sum>m*2+1){
			if (last_y+m+1>=60) printf("%d %d",last_x+1,last_y+m+1-60);
				else printf("%d %d",last_x,last_y+m+1);
			return 0;
		}
		last_x=x,last_y=y;
	}
	if (y+m+1>=60) printf("%d %d",x+1,y+m+1-60);
		else printf("%d %d",x,y+m+1);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n,s;
    cin >> n >> s;
    bool flag=false;
    int t1,t2;
    int h,m;cin >> h >> m;
    t1=h*60+m;
    if(t1>s){
        printf("0 0");
        flag=true;
    }
    for(int i=1;i<n;i++){
        cin >> h >> m;
        if(flag)continue;
        t2=h*60+m;
        if(t2-t1>2*s+2){
            t1+=s+1;
            h=t1/60;
            m=t1%60;
            cout << h << ' ' << m;
            flag=true;
        }
        t1=t2;
    }
    if(!flag){
        t1+=s+1;
        h=t1/60;
        m=t1%60;
        cout << h << ' ' << m;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n,s;
    cin >> n >> s;
    bool flag=false;
    int t1,t2;
    int h,m;cin >> h >> m;
    t1=h*60+m;
    for(int i=1;i<n;i++){
        cin >> h >> m;
        if(flag)continue;
        t2=h*60+m;
        if(t2-t1>2*s+2){
            t1+=s+1;
            h=t1/60;
            m=t1%60;
            cout << h << ' ' << m;
            flag=true;
        }
        t1=t2;
    }
    if(!flag){
        t1+=s+1;
        h=t1/60;
        m=t1%60;
        cout << h << ' ' << m;
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n,s;
    cin >> n >> s;
    bool flag=false;
    int t1,t2;
    int h,m;cin >> h >> m;
    t1=h*60+m;
    if(t1>s){
        printf("0 0");
        flag=true;
    }
    for(int i=1;i<n;i++){
        cin >> h >> m;
        if(flag)continue;
        t2=h*60+m;
        if(t2-t1>=2*s+2){
            t1+=s+1;
            h=t1/60;
            m=t1%60;
            cout << h << ' ' << m;
            flag=true;
        }
        t1=t2;
    }
    if(!flag){
        t1+=s+1;
        h=t1/60;
        m=t1%60;
        cout << h << ' ' << m;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,s;
int h[107];
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
	{
		int a=0,b=0;
		scanf("%d%d",&a,&b);
		h[i]=a*60+b;
		if(i==1&&h[i]>=s+1)
		{
			printf("%d %d",0,0);
			return 0;
		}
		if(h[i]-h[i-1]>=2*s+2)
		{
			int c=h[i-1]+s+1;
			printf("%d %d",c/60,c%60);
			return 0;
		}
	}
	int c=h[n]+s+1;
	printf("%d %d",c/60,c%60);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,s;
int h[107];
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
	{
		int a=0,b=0;
		scanf("%d%d",&a,&b);
		h[i]=a*60+b;
		if(i==1&&h[i]>s+1)
		{
			printf("%d %d",0,0);
			return 0;
		}
		if(h[i]-h[i-1]>2*s+1)
		{
			int c=h[i-1]+s+1;
			printf("%d %d",c/60,c%60);
			return 0;
		}
	}
	int c=h[n]+s+1;
	printf("%d %d",c/60,c%60);
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int n,s;
int h[107];
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
	{
		int a=0,b=0;
		scanf("%d%d",&a,&b);
		h[i]=a*60+b;
		if(i==1&&h[i]>s+1)
		{
			printf("%d %d",0,0);
			return 0;
		}
		if(h[i]-h[i-1]>2*s+2)
		{
			int c=h[i-1]+s+1;
			printf("%d %d",c/60,c%60);
			return 0;
		}
	}
	int c=h[n]+s+1;
	printf("%d %d",c/60,c%60);
	return 0;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+2<mcul2) break;
        if(mcul1+s*2+2 <= mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && i==0) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+2<mcul2) break;
        if(mcul1+s*2+2 < mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+2<mcul2) break;
        if(mcul1+s*2+2 < mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && n>1) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+2<=mcul2) break;
        if(mcul1+s*2+2 <= mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && i==0) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+1<=mcul2) break;
        if(mcul1+s*2+2 <= mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && i==0) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+2<mcul2) break;
        if(mcul1+s*2+2 < mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && i==0) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


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

int main(){
    int i,n,s,h,m,mcul1,mcul2;
    cin>>n>>s;
    mcul1=0;
    for(i=0;i<n;i++){
        cin>>h>>m;
        mcul2=h*60+m;
        if(mcul1==0 && i==0 && s+1<mcul2) break;
        if(mcul1+s*2+2 < mcul2) break;
        mcul1=mcul2;
    }
    if(mcul1==0 && n>=1) s=0;
    else s++;
    h=(mcul1+s)/60;
    m=(mcul1+s)%60;
    cout<<h<<" "<<m<<endl;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define rep(i,s,t) for(int i=s;i<t;++i)
#define INF (0x3f3f3f3f)
using namespace std;
int n,s,h,m,t[105],ans;

int main() {
  scanf("%d%d", &n,&s);
  for(int i=0;i<n;++i) {
    scanf("%d%d", &h,&m);
    t[i] = h*60+m;
  }
  if(t[0]>s+2) ans=0;
  else {
    int f=1;
  for(int i=1;i<n;++i) {
    if( t[i]-t[i-1] > 2*s+1 ) {
      ans = t[i-1]+s+1; f=0;
      break;
    }
  }
  if(f==1) ans=t[n-1]+s+1;
  }
  printf("%d %d\n", ans/60, ans%60 );
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define rep(i,s,t) for(int i=s;i<t;++i)
#define INF (0x3f3f3f3f)
using namespace std;
int n,s,h,m,t[105],ans;

int main() {
  scanf("%d%d", &n,&s);
  for(int i=0;i<n;++i) {
    scanf("%d%d", &h,&m);
    t[i] = h*60+m;
  }
  if(t[0]>=s+2) ans=0;
  else {
    int f=1;
  for(int i=1;i<n;++i) {
    if( t[i]-t[i-1] > 2*s+1 ) {
      ans = t[i-1]+s+1; f=0;
      break;
    }
  }
  if(f==1) ans=t[n-1]+s+1;
  }
  printf("%d %d\n", ans/60, ans%60 );
  return 0;
}


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define clr(x) memset(x,0,sizeof(x))
#define clr_1(x) memset(x,-1,sizeof(x))
#define LL long long
#define mod 1000000007
#define rep(i,s,t) for(int i=s;i<t;++i)
#define INF (0x3f3f3f3f)
using namespace std;
int n,s,h,m,t[105],ans;

int main() {
  scanf("%d%d", &n,&s);
  for(int i=0;i<n;++i) {
    scanf("%d%d", &h,&m);
    t[i] = h*60+m;
  }
  if(t[0]>=s+1) ans=0;
  else {
    int f=1;
  for(int i=1;i<n;++i) {
    if( t[i]-t[i-1] > 2*s+1 ) {
      ans = t[i-1]+s+1; f=0;
      break;
    }
  }
  if(f==1) ans=t[n-1]+s+1;
  }
  printf("%d %d\n", ans/60, ans%60 );
  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

int n,s;
int h[105],m[105];

int minus(int h1,int m1,int h2,int m2) {
	int ans=0;
	if(m2>=m1) ans=m2-m1+60*(h2-h1);
	else {
		ans=m2+60-m1+60*(h2-h1-1);
	}
	return ans;
}

int main() {
	scanf("%d%d",&n,&s);
	h[0]=m[0]=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&h[i],&m[i]);
	}
	int hh=0;
	int mm=0;
	int f=0;
	for(int i=1;i<=n;i++) {
		if(minus(h[i-1],m[i-1],h[i],m[i])-2 >= 2*s) {
//			printf("minus=%d\n",minus(0,30,1,0));
			hh=h[i-1];
			mm=m[i-1]+1+s;
			if(mm>=60) {
				hh+=mm/60;
				mm%=60;
			}
			f=1;
			break;
		}
	}
	if(!f) {
		hh=h[n];
		mm=m[n]+1+s;
		if(mm>=60) {
			hh+=mm/60;
			mm%=60;
		}
	}
	int ansh=0;
	int ansm=0;
	if(mm>=m[0]) {
		ansm=mm-m[0];
		ansh=hh-h[0];
	}
	else {
		ansm=mm+60-m[0];
		ansh=hh-h[0]-1;
	}
	printf("%d %d\n",ansh,ansm);
}


#include<cstdio>
#include<algorithm>
using namespace std;

int n,s;
int h[105],m[105];

int minus(int h1,int m1,int h2,int m2) {
	int ans=0;
	if(m2>=m1) ans=m2-m1+60*(h2-h1);
	else {
		ans=m2+60-m1+60*(h2-h1-1);
	}
	return ans;
}

int main() {
	scanf("%d%d",&n,&s);
	h[0]=m[0]=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&h[i],&m[i]);
	}
	int hh=0;
	int mm=0;
	int f=0;
	for(int i=1;i<n;i++) {
		if(minus(h[i-1],m[i-1],h[i],m[i])-2 >= 2*s) {
//			printf("minus=%d\n",minus(0,30,1,0));
			hh=h[i-1];
			mm=m[i-1]+1+s;
			if(mm>=60) {
				hh+=mm/60;
				mm%=60;
			}
			f=1;
			break;
		}
	}
	if(!f) {
		hh=h[n];
		mm=m[n]+1+s;
		if(mm>=60) {
			hh+=mm/60;
			mm%=60;
		}
	}
	int ansh=0;
	int ansm=0;
	if(mm>=m[0]) {
		ansm=mm-m[0];
		ansh=hh-h[0];
	}
	else {
		ansm=mm+60-m[0];
		ansh=hh-h[0]-1;
	}
	printf("%d %d\n",ansh,ansm);
}


#include<cstdio>
#include<algorithm>
using namespace std;

int n,s;
int h[105],m[105];

int minus(int h1,int m1,int h2,int m2) {
	int ans=0;
	if(m2>=m1) ans=m2-m1+60*(h2-h1);
	else {
		ans=m2+60-m1+60*(h2-h1-1);
	}
	return ans;
}

int main() {
	scanf("%d%d",&n,&s);
	h[0]=m[0]=0;
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&h[i],&m[i]);
	}
	int hh=0;
	int mm=0;
	int f=0;
	for(int i=1;i<n;i++) {
		if(minus(h[i-1],m[i-1],h[i],m[i])-2 >= 2*s) {
//			printf("minus=%d\n",minus(0,30,1,0));
			hh=h[i-1];
			mm=m[i-1]+1+s;
			if(mm>=60) {
				hh+=mm/60;
				mm%=60;
			}
			f=1;
			break;
		}
	}
	if(!f) {
		hh=h[n];
		mm=m[n]+1+s;
		if(mm>=60) {
			hh+=mm/60;
			mm%=60;
		}
	}
	int ansh=0;
	int ansm=0;
	if(mm>=m[0]) {
		ansm=mm-m[0];
		ansh=hh-h[0];
	}
	else {
		ansm=mm+60-m[0];
		ansh=hh-h[0]-1;
	}
	printf("%d %d\n",ansh%25,ansm);
}


#include<iostream>
using namespace std;
int main(void) {
	int n, s, hour[101], minute[101], flag=1, i;
	cin >> n >> s;
	cin >> hour[0] >> minute[0];
	if (hour[0] * 60 + minute[0] > s + 1) {
		flag = 0;
		cout << "0 0";
	}
	else{
		for (i = 1; i < n; ++i) {
			cin >> hour[i] >> minute[i];
			if ((hour[i] - hour[i - 1]) * 60 + minute[i] - minute[i - 1] > 2*s + 1) {
				cout<< hour[i - 1] + (minute[i - 1] + s + 1) / 60 <<" "<< (minute[i - 1] + s + 1) % 60;
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		cout << hour[i - 1] + (minute[i - 1] + s + 1) / 60 << " " << (minute[i - 1] + s + 1) % 60;
}


#include<iostream>
using namespace std;
int main(void) {
	int n, s, hour[101], minute[101], flag=1, i;
	cin >> n >> s;
	cin >> hour[0] >> minute[0];
	if (hour[0] * 60 + minute[0] > s + 1) {
		flag = 0;
		cout << "0 0";
	}
	else{
		for (i = 1; i < n; ++i) {
			cin >> hour[i] >> minute[i];
			if ((hour[i] - hour[i - 1]) * 60 + minute[i] - minute[i - 1] > 2*s) {
				cout<< hour[i - 1] + (minute[i - 1] + s + 1) / 60 <<" "<< (minute[i - 1] + s + 1) % 60;
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		cout << hour[i - 1] + (minute[i - 1] + s + 1) / 60 << " " << (minute[i - 1] + s + 1) % 60;
}


#include<iostream>
using namespace std;
int main(void) {
	int n, s, hour[101], minute[101], flag=1, i;
	cin >> n >> s;
	cin >> hour[0] >> minute[0];
	if (hour[0] * 60 + minute[0] > s + 1) {
		flag = 0;
		cout << "0 0";
	}
	else{
		for (i = 1; i < n; ++i) {
			cin >> hour[i] >> minute[i];
			if ((hour[i] - hour[i - 1]) * 60 + minute[i] - minute[i - 1] > 2*s + 2) {
				cout<< hour[i - 1] + (minute[i - 1] + s + 1) / 60 <<" "<< (minute[i - 1] + s + 1) % 60;
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		cout << hour[i - 1] + (minute[i - 1] + s + 1) / 60 << " " << (minute[i - 1] + s + 1) % 60;
}


#include<iostream>
using namespace std;
int main(void) {
	int n, s, hour[101], minute[101], flag=1, i;
	cin >> n >> s;
	cin >> hour[0] >> minute[0];
	if (hour[0] * 60 + minute[0] > s + 1) {
		flag = 0;
		cout << "0 0";
	}
	else{
		for (i = 1; i < n; ++i) {
			cin >> hour[i] >> minute[i];
			if ((hour[i] - hour[i - 1]) * 60 + minute[i] - minute[i - 1] > 2*s + 3) {
				cout<< hour[i - 1] + (minute[i - 1] + s + 1) / 60 <<" "<< (minute[i - 1] + s + 1) % 60;
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		cout << hour[i - 1] + (minute[i - 1] + s + 1) / 60 << " " << (minute[i - 1] + s + 1) % 60;
}


#include<iostream>
using namespace std;
int main(void) {
	int n, s, hour[101], minute[101], flag=1, i;
	cin >> n >> s;
	cin >> hour[0] >> minute[0];
	if (hour[0] * 60 + minute[0] > s) {
		flag = 0;
		cout << "0 0";
	}
	else{
		for (i = 1; i < n; ++i) {
			cin >> hour[i] >> minute[i];
			if ((hour[i] - hour[i - 1]) * 60 + minute[i] - minute[i - 1] > 2*s + 1) {
				cout<< hour[i - 1] + (minute[i - 1] + s + 1) / 60 <<" "<< (minute[i - 1] + s + 1) % 60;
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		cout << hour[i - 1] + (minute[i - 1] + s + 1) / 60 << " " << (minute[i - 1] + s + 1) % 60;
}


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

struct node
{
    int hour;
    int minutes;
    int minutesValue;
    struct node *next;
};

struct node *newNode (struct node *top, int hour, int minutes)
{
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->hour = hour;
    newNode->minutes = minutes;
    if (top==NULL)
    {
        top = newNode;
        top->next = NULL;
    }
    else
    {
        top->next = newNode;
        newNode->next = NULL;

    }
    return newNode;
};

struct node *addHead (struct node *top, int hour, int minutes)
{
    node *newNode = new node;
    newNode->hour;
    newNode->minutes;
    newNode->next = top;
    return newNode;
};

int main()
{
    int numOfLanding, minGap, hour, minutes;
    int tempMinutesValue, hourOutput, minuteOutput;
    bool firstCheck = false;
    cin>>numOfLanding;
    cin>>minGap;
    cout<<endl;

    struct node *head = NULL;
    struct node *tail = NULL;

    for (int i=0; i<numOfLanding; i++)
    {
        cin>>hour;
        cin>>minutes;
        if (head==NULL)
        {
            head=newNode(head, hour, minutes);
            head->minutesValue=(head->hour*60)+head->minutes;
            tail=head;
        }
        else
        {
            tail=newNode(tail, hour, minutes);
            tail->minutesValue=(tail->hour*60)+tail->minutes;
        }
    }

    struct node *temp;
    temp = head;
    struct node *tempAhead = temp->next;

    while (true)
    {
        if (temp->minutesValue-(minGap+1)>=0&&firstCheck==false)
        {
            cout<<"0"<<" "<<"0";
            break;
        }

        else if ((temp->minutesValue+((minGap*2)+1))<tempAhead->minutesValue)
        {
            cout<<"Goes to the second loop"<<endl;
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%hourOutput;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
        firstCheck = true;
        temp=temp->next;
        if (tempAhead->next!=NULL)
        {
            tempAhead=tempAhead->next;
        }
        else
        {
            cout<<"Goes to the third loop"<<endl;
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
    }

    return 0;
}


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

struct node
{
    int hour;
    int minutes;
    int minutesValue;
    struct node *next;
};

struct node *newNode (struct node *top, int hour, int minutes)
{
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->hour = hour;
    newNode->minutes = minutes;
    if (top==NULL)
    {
        top = newNode;
        top->next = NULL;
    }
    else
    {
        top->next = newNode;
        newNode->next = NULL;

    }
    return newNode;
};

struct node *addHead (struct node *top, int hour, int minutes)
{
    node *newNode = new node;
    newNode->hour;
    newNode->minutes;
    newNode->next = top;
    return newNode;
};

int main()
{
    int numOfLanding, minGap, hour, minutes;
    int tempMinutesValue, hourOutput, minuteOutput;
    bool firstCheck = false;
    cin>>numOfLanding;
    cin>>minGap;
    cout<<endl;

    struct node *head = NULL;
    struct node *tail = NULL;

    for (int i=0; i<numOfLanding; i++)
    {
        cin>>hour;
        cin>>minutes;
        if (head==NULL)
        {
            head=newNode(head, hour, minutes);
            head->minutesValue=(head->hour*60)+head->minutes;
            tail=head;
        }
        else
        {
            tail=newNode(tail, hour, minutes);
            tail->minutesValue=(tail->hour*60)+tail->minutes;
        }
    }

    struct node *temp;
    temp = head;
    struct node *tempAhead = temp->next;

    while (true)
    {
        if (temp->minutesValue-(minGap+1)>=0&&firstCheck==false)
        {
            cout<<"0"<<" "<<"0";
            break;
        }

        else if ((temp->minutesValue+((minGap*2)+1))<tempAhead->minutesValue)
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%hourOutput;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
        firstCheck = true;
        temp=temp->next;
        if (tempAhead->next!=NULL)
        {
            tempAhead=tempAhead->next;
        }
        else
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
    }

    return 0;
}


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

struct node
{
    int hour;
    int minutes;
    int minutesValue;
    struct node *next;
};

struct node *newNode (struct node *top, int hour, int minutes)
{
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->hour = hour;
    newNode->minutes = minutes;
    if (top==NULL)
    {
        top = newNode;
        top->next = NULL;
    }
    else
    {
        top->next = newNode;
        newNode->next = NULL;

    }
    return newNode;
};

struct node *addHead (struct node *top, int hour, int minutes)
{
    node *newNode = new node;
    newNode->hour;
    newNode->minutes;
    newNode->next = top;
    return newNode;
};

int main()
{
    int numOfLanding, minGap, hour, minutes;
    int tempMinutesValue, hourOutput, minuteOutput;
    bool firstCheck = false;
    cin>>numOfLanding;
    cin>>minGap;
    cout<<endl;

    struct node *head = NULL;
    struct node *tail = NULL;

    for (int i=0; i<numOfLanding; i++)
    {
        cin>>hour;
        cin>>minutes;
        if (head==NULL)
        {
            head=newNode(head, hour, minutes);
            head->minutesValue=(head->hour*60)+head->minutes;
            tail=head;
        }
        else
        {
            tail=newNode(tail, hour, minutes);
            tail->minutesValue=(tail->hour*60)+tail->minutes;
        }
    }

    struct node *temp;
    temp = head;
    struct node *tempAhead = temp->next;

    while (true)
    {
        if (temp->minutesValue-(minGap+1)>=0&&firstCheck==false)
        {
            cout<<"0"<<" "<<"0";
            break;
        }

        else if ((temp->minutesValue+((minGap*2)+1))<tempAhead->minutesValue)
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
        firstCheck = true;
        temp=temp->next;
        if (tempAhead->next!=NULL)
        {
            tempAhead=tempAhead->next;
        }
        else
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
    }

    return 0;
}


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

struct node
{
    int hour;
    int minutes;
    int minutesValue;
    struct node *next;
};

struct node *newNode (struct node *top, int hour, int minutes)
{
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->hour = hour;
    newNode->minutes = minutes;
    if (top==NULL)
    {
        top = newNode;
        top->next = NULL;
    }
    else
    {
        top->next = newNode;
        newNode->next = NULL;

    }
    return newNode;
};

struct node *addHead (struct node *top, int hour, int minutes)
{
    node *newNode = new node;
    newNode->hour;
    newNode->minutes;
    newNode->next = top;
    return newNode;
};

int main()
{
    int numOfLanding, minGap, hour, minutes;
    int tempMinutesValue, hourOutput, minuteOutput;
    bool firstCheck = false;
    cin>>numOfLanding;
    cin>>minGap;
    cout<<endl;

    struct node *head = NULL;
    struct node *tail = NULL;

    for (int i=0; i<numOfLanding; i++)
    {
        cin>>hour;
        cin>>minutes;
        if (head==NULL)
        {
            head=newNode(head, hour, minutes);
            head->minutesValue=(head->hour*60)+head->minutes;
            tail=head;
        }
        else
        {
            tail=newNode(tail, hour, minutes);
            tail->minutesValue=(tail->hour*60)+tail->minutes;
        }
    }

    struct node *temp;
    temp = head;
    struct node *tempAhead = temp->next;

    while (true)
    {
        if (temp->minutesValue-(minGap+1)>=0&&firstCheck==false)
        {
            cout<<"0"<<" "<<"0";
            break;
        }

        else if ((temp->minutesValue+((minGap*2)+1))<tempAhead->minutesValue)
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            hourOutput = tempMinutesValue/60;
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
        firstCheck = true;
        temp=temp->next;
        if (tempAhead->next!=NULL)
        {
            tempAhead=tempAhead->next;
        }
        else
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            if (tempMinutesValue>=60)
            {
                hourOutput = tempMinutesValue/60;
            }
            else
            {
                hourOutput = 0;
            }
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
    }

    return 0;
}


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

struct node
{
    int hour;
    int minutes;
    int minutesValue;
    struct node *next;
};

struct node *newNode (struct node *top, int hour, int minutes)
{
    struct node *newNode = (struct node*)malloc(sizeof(struct node));
    newNode->hour = hour;
    newNode->minutes = minutes;
    if (top==NULL)
    {
        top = newNode;
        top->next = NULL;
    }
    else
    {
        top->next = newNode;
        newNode->next = NULL;

    }
    return newNode;
};

struct node *addHead (struct node *top, int hour, int minutes)
{
    node *newNode = new node;
    newNode->hour;
    newNode->minutes;
    newNode->next = top;
    return newNode;
};

int main()
{
    int numOfLanding, minGap, hour, minutes;
    int tempMinutesValue, hourOutput, minuteOutput;
    bool firstCheck = false;
    cin>>numOfLanding;
    cin>>minGap;
    cout<<endl;

    struct node *head = NULL;
    struct node *tail = NULL;

    for (int i=0; i<numOfLanding; i++)
    {
        cin>>hour;
        cin>>minutes;
        if (head==NULL)
        {
            head=newNode(head, hour, minutes);
            head->minutesValue=(head->hour*60)+head->minutes;
            tail=head;
        }
        else
        {
            tail=newNode(tail, hour, minutes);
            tail->minutesValue=(tail->hour*60)+tail->minutes;
        }
    }

    struct node *temp;
    temp = head;

    while (true)
    {
        if (temp->minutesValue-(minGap+1)>=0&&firstCheck==false)
        {
            cout<<"0"<<" "<<"0";
            break;
        }
        firstCheck = true;
        if (temp->next!=NULL)
        {
            if ((temp->minutesValue+((minGap*2)+1))<temp->next->minutesValue)
            {
                tempMinutesValue = temp->minutesValue+minGap+1;
                if (tempMinutesValue>=60)
                {
                    hourOutput = tempMinutesValue/60;
                }
                else
                {
                    hourOutput = 0;
                }
                minuteOutput = tempMinutesValue%60;
                cout<<hourOutput<<" "<<minuteOutput<<endl;
                break;
            }
            temp = temp->next;
        }
        else
        {
            tempMinutesValue = temp->minutesValue+minGap+1;
            if (tempMinutesValue>=60)
            {
                hourOutput = tempMinutesValue/60;
            }
            else
            {
                hourOutput = 0;
            }
            minuteOutput = tempMinutesValue%60;
            cout<<hourOutput<<" "<<minuteOutput<<endl;
            break;
        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,s;
bool ok[1501];
int main(){
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        int h,m;
        cin>>h>>m;
        int t=h*60+m;
        for(int i=max(0,t-s);i<=t+s;i++)ok[i]=1;
    }
    for(int i=0;i<=1500;i++)
    if(!ok[i]){
        int h=i/60,m=i%60;
        cout<<h<<""<<m<<endl;
        break;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,s;
bool ok[1501];
int main(){
    memset(ok,1,sizeof(ok));
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        int h,m;
        cin>>h>>m;
        int t=h*60+m;
        for(int i=max(0,t-s);i<=t+s;i++)ok[i]=0;
    }
    for(int i=0;i<=1500;i++)
    if(ok[i]){
        int h=i/60,m=i%60;
        cout<<h<<""<<m<<endl;
        break;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n,s;
bool ok[1501];
int main(){
    cin>>n>>s;
    for(int i=1;i<=n;i++){
        int h,m;
        cin>>h>>m;
        int t=h*60+m;
        for(int i=max(0,t-s);i<=t+s;i++)ok[i]=1;
    }
    for(int i=0;i<=1500;i++)
    if(!ok[i]){
        int h=i/60,m=i%60;
        cout<<h<<" "<<m<<endl;
        break;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz 100005
#define szz 25005
#define PI 3.14159265

using namespace std;

class code
{
public:
    ll h,m;
};

code arr[sz];

int main()
{
    ll n,s;

    scanf("%lld %lld",&n,&s);

    for(ll i=1; i<=n; i++)
    {
        scanf("%lld %lld",&arr[i].h,&arr[i].m);
    }

    arr[0].h=0;
    arr[0].m=0;

    ll ss=arr[1].h,ff=arr[1].m;

    if(ff<s)
    {
        ss--;
        ff=(ff+60)-s;
    }

    else
    {
        ff=ff-s;
    }

    // printf("%lld %lld\n",ss,ff);

    ll gg=0;

    if(ss>=0)
    {
        if(ss>=1||ff>=1)
        {
            printf("0 0\n");
            gg=1;
        }
    }

    if(gg==0)
    {
        ll flag=0;

        for(ll i=2; i<=n; i++)
        {
            ll aa=arr[i-1].h;
            ll bb=arr[i-1].m;
            ll xx=arr[i].h;
            ll yy=arr[i].m;

            bb+=(s+1);

            if(bb>=60)
            {
                ll r=(bb/60);

                bb=bb-(r*60);
                aa+=r;
            }

            if(yy<s)
            {
                xx--;
                yy=(yy+60)-s;
            }

            else
            {
                yy=yy-s;
            }

            if(aa<xx)
            {
                printf("%lld %lld\n",aa,bb);
                flag=1;
                break;
            }

            else if(aa==xx)
            {
                if(bb<yy)
                {
                    printf("%lld %lld\n",aa,bb);
                    flag=1;
                    break;
                }
            }
        }

        if(flag==0)
        {
            arr[n].m+=(s+1);

            if(arr[n].m>=60)
            {
                ll r=(arr[n].m)/60;

                arr[n].h+=r;
                arr[n].m=arr[n].m-(r*60);
            }

            printf("%lld %lld\n",arr[n].h, arr[n].m);
        }
    }

    return (0);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz 100005
#define szz 25005
#define PI 3.14159265

using namespace std;

class code
{
public:
    ll h,m;
};

code arr[sz];

int main()
{
    ll n,s;

    scanf("%lld %lld",&n,&s);

    for(ll i=1; i<=n; i++)
    {
        scanf("%lld %lld",&arr[i].h,&arr[i].m);
    }

    arr[0].h=0;
    arr[0].m=0;

    ll ss=arr[1].h,ff=arr[1].m;

    if(ff<s)
    {
        ss--;
        ff=(ff+60)-s;
    }

    else
    {
        ff=ff-s;
    }

    if(ss>=0&&ff>=1)
    {
        printf("0 0\n");
    }

    else
    {
        ll flag=0;

        for(ll i=2; i<=n; i++)
        {
            ll aa=arr[i-1].h;
            ll bb=arr[i-1].m;
            ll xx=arr[i].h;
            ll yy=arr[i].m;

            bb+=(s+1);

            if(bb>=60)
            {
                bb=bb-60;
                aa+=1;
            }

            if(yy<s)
            {
                xx--;
                yy=(yy+60)-s;
            }

            else
            {
                yy=yy-s;
            }

            if(aa<xx)
            {
                printf("%lld %lld\n",aa,bb);
                flag=1;
                break;
            }

            else if(aa==xx)
            {
                if(bb<yy)
                {
                    printf("%lld %lld\n",aa,bb);
                    flag=1;
                    break;
                }
            }
        }

        if(flag==0)
        {
            arr[n].m+=(s+1);

            if(arr[n].m>=60)
            {
                arr[n].h+=1;
                arr[n].m=arr[n].m-60;
            }

            printf("%lld %lld\n",arr[n].h, arr[n].m);
        }
    }

    return (0);
}