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


int length_last(string str)
{
    int count = 0;
    bool flag = false;
    for (int i = str.length() - 1; i >= 0; i--) {
        if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')) {
            flag = true;
            count++;
        }
        else {
            if (flag == true)
                return count;
        }
    }
    return count;
}

int solve(string s1, string s2, char c, int i){
	string temp = s1;
	s1 = s1.substr(i, s1.length());
	if(c == 'Y'){
		size_t f1 = s1.find(s2 + " ");
    	if (f1 != string::npos && i+f1 == 0)
        	return i+f1;
    	size_t f2 = s1.find(" " + s2 + " ");
    	if (f2 != string::npos)
    		return i+f2+1;
    	size_t f3  = s1.find_last_of(" " + s2);
    	// cout<<i+f3;
    	// cout<<temp.length();
    	if (f3 != string::npos)
    		return (i+f3)-length_last(temp)+1;
	}
	else {
		size_t found = s1.find(s2);
		if (found != string::npos)
        	return i+found;
	}
	return -1;
}
int main() {
	string s1,s2;
	char c;
	int i;
	s1 = "hack on hacker hack";
	s2 = "hack";
	c = 'Y';
	i = 7;
	int ans = solve(s1, s2, c, i);
	if(ans == -1)
		cout<<"Goodbye Watson"<<endl;
	else
		cout<<ans<<endl;
	return 0;
}