#include <bits/stdc++.h>
using namespace std;
int z[1234567];
string s, a;
void z_cal(void) {
  int n = s.size();
  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++;
      z[i] = r - l;
      r--;
    } else {
      k = i - l;
      if (z[k] < r - i + 1)
        z[i] = z[k];
      else {
        l = i;
        while (r < n && s[r - l] == s[r]) r++;
        z[i] = r - l;
        r--;
      }
    }
  }
}
int main() {
  cin >> s;
  z_cal();
  int ans = -1;
  int mx = 0;
  for (int i = 1; i < s.size(); i++) {
    if (z[i] == s.size() - i) {
      if (mx >= z[i]) {
        ans = i;
        break;
      }
    }
    mx = max(mx, z[i]);
  }
  if (ans == -1)
    puts("Just a legend");
  else
    cout << s.substr(ans) << endl;
  return 0;
}
