#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
string s;
int z[N], freq[N], sum[N], l = -1, r = -1, ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  int n = s.length();
  for (int i = int(1); i <= int(n - 1); i++) {
    if (i > r) {
      while (z[i] + i < n && s[i + z[i]] == s[z[i]]) z[i]++;
      if (z[i]) l = i, r = z[i] - 1 + i;
    } else {
      z[i] = min(z[i - l], r - i + 1);
      while (z[i] + i < n && s[i + z[i]] == s[z[i]]) z[i]++;
      if (z[i] + i - 1 > r) r = z[i] - 1 + i, l = i;
    }
  }
  int ans = 0, mx = 0;
  for (int i = int(1); i <= int(n); i++) {
    if (z[i] == n - i && z[i] <= mx) {
      ans = z[i];
      break;
    }
    mx = max(mx, z[i]);
  }
  if (ans == 0)
    cout << "Just a legend";
  else
    for (int i = int(0); i <= int(ans - 1); i++) cout << s[i];
  cout << '\n';
  return 0;
}
