#include <bits/stdc++.h>
using namespace std;
int z[1000001];
void z_algo(string s) {
  z[0] = (int)s.length();
  int i;
  int l, r, k;
  l = 0, r = 0;
  int n = s.length();
  for (i = 1; i < n; i++) {
    if (r < i) {
      l = i;
      r = i;
      while (r < n && s[r - l] == s[r]) r++;
      z[i] = r - l;
      r--;
    } else {
      k = i - l;
      if (z[k] < r - i + 1)
        z[i] = z[k];
      else {
        l = i;
        while (r < n && s[r - l] == s[r]) r++;
        z[i] = r - l;
        r--;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  z_algo(s);
  set<int> se;
  z[0] = 1;
  int fre[27] = {0};
  for (int i = 0; i < s.length(); i++) {
    fre[s[i] - 'a']++;
  }
  se.insert(z[0]);
  if (s.length() <= 2) {
    cout << "Just a legend" << endl;
    return 0;
  }
  for (int i = 1; i < s.length() - 1; i++) {
    if (i + z[i] == (s.length())) {
      if (se.size() > 0 && *(se.rbegin()) >= z[i]) {
        cout << s.substr(0, z[i]) << endl;
        return 0;
      }
      se.insert(z[i]);
    } else
      se.insert(z[i]);
  }
  if (s[0] == s[(int)s.length() - 1] && fre[s[0] - 'a'] > 2) {
    cout << s[0] << endl;
    return 0;
  }
  cout << "Just a legend" << endl;
  return 0;
}
