#include <bits/stdc++.h>
using namespace std;
vector<int> zfunction(string s) {
  vector<int> z(s.size());
  for (int i = 1, l = 0, r = 0; i < s.size(); i++) {
    if (i <= r) z[i] = (r - i + 1 < z[i - l] ? r - i + 1 : z[i - l]);
    while (i + z[i] < s.size() && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int main() {
  string s;
  cin >> s;
  vector<int> z = zfunction(s);
  set<int> foo;
  int ans = -1;
  for (int i = 0; i < s.size(); i++) {
    if (z[i] == s.size() - i && foo.lower_bound(z[i]) != foo.end() &&
        z[i] != 0) {
      ans = z[i];
      break;
    }
    foo.insert(z[i]);
  }
  if (ans == -1)
    puts("Just a legend");
  else
    cout << s.substr(0, ans) << endl;
}
