#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(1000005);
int z[MAXN];
void z_function(string s) {
  int n = s.size(), l = 0, r = 0;
  for (int i = 1; i <= n - 1; 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 a;
  cin >> a;
  int n = a.size();
  z_function(a);
  int ans = 0, idx = -1, best = z[1];
  for (int i = 2; i <= n - 1; i++) {
    if (z[i] == n - i && best >= z[i]) {
      if (z[i] > ans) {
        ans = z[i];
        idx = i;
      }
    }
    best = max(best, z[i]);
  }
  if (idx == -1)
    printf("Just a legend");
  else
    cout << a.substr(0, z[idx]);
}
