#include <bits/stdc++.h>
using namespace std;
int main() {
  int pi, mxl = 0;
  string s;
  cin >> s;
  int n = s.length();
  auto p = vector<int>(n);
  p[0] = pi = -1;
  for (int i = 1; i < n; i++) {
    while (pi != -1 && s[pi + 1] != s[i]) pi = p[pi];
    if (s[pi + 1] == s[i]) pi++;
    p[i] = pi;
  }
  for (int i = n - 1; p[i] != -1; i = p[i]) {
    for (int k = 1; k <= n - 2; k++)
      if (p[k] == p[i]) {
        mxl = p[i] + 1;
        break;
      }
    if (mxl != 0) break;
  }
  string ans = mxl == 0 ? "Just a legend" : s.substr(0, mxl);
  cout << ans << endl;
  return 0;
}
