#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
//int randt(int l, int r){ return (rando() % (r - l + 1) + l); }

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5;
int mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
ll infll = 1e18 + 7;

string s;
int a[26];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> s;
    if (s.length() == 2 && s[0] == s[1]){
        cout << 1<< ' '<< 2;
        return 0;
    }
    For(i, 2, s.length()){
        mset(a);
        a[s[i - 2] - 'a']++;
        a[s[i - 1] - 'a']++;
        a[s[i] - 'a']++;
        For(j, 0, 26){
            if (a[j] == 2){
                cout << i - 1 << ' ' << i + 1 << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << endl;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/
#include<iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, vis[1009], vis2[1009],par[1009],go[1009][1009] ;
vector<int> v[1009];
vector<int> ans;
void solve()
{
    int sz=ans.size();
    for(int i=0; i<sz; i++)
    {
        for(int j=i+2; j<sz; j++)
            if(go[ans[i]][ans[j]])
            {
                ans.erase(ans.begin()+i+1,ans.begin()+j);
                solve();
                return ;
            }
        int j=0;
        if(i==sz-1)
            j=1;
        for(; j<i; j++)
            if(go[ans[i]][ans[j]])
            {
                ans.erase(ans.begin()+i+1,ans.end());
                ans.erase(ans.begin(),ans.begin()+j);
                solve();
                return ;
            }
    }
    cout<<ans.size()<<endl;
    for(auto i : ans)
        cout<<i<<"\n";
}
void dfs(int node)
{
    if(vis2[node])
    {
        int x=node;
        while(par[x]!=node)
            ans.push_back(x), x=par[x];
        ans.push_back(x);
        reverse(ans.begin(),ans.end());
        solve();
        exit(0);
    }
    if(vis[node])
        return ;
    vis2[node]++;
    vis[node]++;
    for(auto i : v[node])
    {
        par[i]=node;
        dfs(i);
    }
    vis2[node]--;
}
int main()
{
    IO
    cin>>n>>m;
    while(m--)
    {
        int x, y ;
        cin>>x>>y;
        go[x][y]=1;
        v[x].push_back(y);
    }
    for(int i=1; i<=n; i++)
        dfs(i);
    cout<<-1;
    return 0;
}
