#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
string s;
int n, L, R, z[maxn], mx;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  n = s.size();
  for (int i = 1; i < n; i++)
    if (i > R) {
      L = R = i;
      while (R < n && s[R] == s[R - L]) R++;
      z[i] = R - L;
      R--;
    } else if (z[i - L] > R - i) {
      L = i;
      while (R < n && s[R] == s[R - L]) R++;
      z[i] = R - L;
      R--;
    } else
      z[i] = z[i - L];
  for (int i = 1; i < n; i++) {
    if (z[i] == n - i && mx >= z[i]) {
      for (int ind = 0; ind < z[i]; ind++) cout << s[ind];
      cout << "\n";
      return 0;
    }
    mx = max(mx, z[i]);
  }
  cout << "Just a legend\n";
  return 0;
}
