#include <bits/stdc++.h>
using namespace std;
vector<int> findz(string s) {
  int n = s.length();
  vector<int> zarr(n, 0);
  int l, r, k;
  l = r = 0;
  for (int i = 1; i < n; i++) {
    if (i > r) {
      l = r = i;
      while (r < n && s[r - l] == s[r]) r++;
      zarr[i] = r - l;
      r--;
    } else {
      k = i - l;
      if (i + zarr[k] - 1 < r) {
        zarr[i] = zarr[k];
      } else {
        l = i;
        while (r < n && s[r - l] == s[r]) r++;
        zarr[i] = r - l;
        r--;
      }
    }
  }
  return zarr;
}
int main() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> zpre = findz(s);
  int max_so_far = 0;
  for (int i = 0; i < n; i++) {
    if (zpre[i] == n - i && max_so_far >= n - i) {
      int id = n - i;
      for (int j = 0; j < id; j++) printf("%c", s[j]);
      return 0;
    }
    max_so_far = max(max_so_far, zpre[i]);
  }
  cout << "Just a legend" << endl;
  return 0;
}
