#include <bits/stdc++.h>
using namespace std;
vector<int> getZ(string &s) {
  int n = s.length();
  vector<int> z(n);
  int l = -1;
  int r = -1;
  for (int i = 1; i < n - 1 + 1; ++i) {
    if (r > i) {
      z[i] = min(z[i - l], r - i + 1);
    }
    while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
    if (i + z[i] > r) {
      l = i;
      r = i + z[i] - 1;
    }
  }
  return z;
}
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  ;
  int n = s.length();
  auto z = getZ(s);
  int longestInfix = 0;
  for (int i = 1; i < n - 1 + 1; ++i)
    if (z[i] > 0) {
      longestInfix = max(longestInfix, min(n - i - 1, z[i]));
    };
  pair<int, int> bestMatch = make_pair(0, 0);
  for (int i = 1; i < n - 1 + 1; ++i)
    if (i + z[i] - 1 == n - 1 && z[i] <= longestInfix) {
      { bestMatch = max(bestMatch, make_pair(z[i], i)); };
    }
  if (bestMatch.first == 0)
    cout << "Just a legend";
  else {
    for (int i = 0; i < bestMatch.first - 1 + 1; ++i)
      cout << s[bestMatch.second + i];
  }
}
