#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 10;
int l[N];
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = ((int)(s).size());
  l[0] = -1;
  for (int i = (1); i <= (n); i++) {
    l[i] = l[i - 1];
    while (l[i] != -1 && s[i - 1] != s[l[i]]) l[i] = l[l[i]];
    l[i]++;
  }
  if (l[n] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = (0); i <= (n - 1); i++)
    if (l[i] == l[n]) {
      for (int j = (0); j <= (l[i] - 1); j++) cout << s[j];
      cout << '\n';
      return 0;
    }
  if (l[l[n]] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = (0); i <= (n - 1); i++)
    if (l[i] == l[l[n]]) {
      for (int j = (0); j <= (l[l[n]] - 1); j++) cout << s[j];
      cout << '\n';
      return 0;
    }
  return 0;
}
