#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int inf = 0x3f3f3f3f;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long power(long long a, long long b, long long m = 1000000007) {
  long long answer = 1;
  while (b) {
    if (b & 1) answer = (answer * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return answer;
}
using namespace std;
vector<int> z_function(string second) {
  int n = (int)second.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && second[z[i]] == second[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int pi[1000000 + 5];
void kmpPreprocess(string &P) {
  int i = 0, j = -1, m = P.size();
  pi[0] = -1;
  while (i < m) {
    while (j >= 0 and P[i] != P[j]) j = pi[j];
    i++, j++;
    pi[i] = j;
  }
}
int main() {
  string p;
  cin >> p;
  vector<int> z;
  z = z_function(p);
  kmpPreprocess(p);
  int mx = 0;
  string h = "";
  int n = p.length();
  bool flag = true;
  if (pi[n] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (pi[n] == pi[i]) {
      for (int j = 0; j < pi[i]; j++) cout << p[j];
      return 0;
    }
  }
  if (pi[pi[n]] == 0) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = 0; i < pi[pi[n]]; i++) cout << p[i];
  return 0;
}
