#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

    int i = 1;
    while (++i <= n) {
        int x = i;
        if (x % 3 == 0) {
            cout << ' ' << i;
        }
        else{
            while (x > 0) {
                if (x % 10 == 3) {
                    cout << ' ' << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s;
    cin>>s;
    vector<string>week={"SAT","FRI","THU","WED","TUE","MON","SUN"};
    rep(i,7){
        if(s==week.at(i)){
            cout<<i+1<<endl;
        }
    }
}