#include <bits/stdc++.h>
using namespace std;
vector<int> z;
void z_function(string s) {
  int n = s.size();
  z.resize(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
}
int main() {
  string s;
  cin >> s;
  string q = s + '#' + s;
  z_function(q);
  int ans = 0, curmax = 0;
  for (int i = s.size() + 2; i < z.size(); ++i) {
    if (z.size() - i == z[i] && curmax >= z[i])
      ans = max(ans, z[i]), curmax = z[i] - 1;
    else
      curmax = max(curmax, z[i]);
  }
  if (ans == 0)
    cout << "Just a legend";
  else
    for (int i = 0; i < ans; ++i) cout << s[i];
}
