#include <bits/stdc++.h>
using namespace std;
vector<int> Z_Algorithm(const string& s) {
  int n = s.size();
  vector<int> Z(n);
  int L = 0, R = 0;
  for (int i(1); i < (n); ++i) {
    if (R > i) {
      if (Z[i - L] + i >= R) {
        L = i;
        Z[i] = R - i;
        for (int j(R); j < (n); ++j) {
          if (s[j] == s[j - i]) {
            ++Z[i];
          } else
            break;
        }
        R = i + Z[i] - 1;
      } else {
        Z[i] = Z[i - L];
      }
    } else {
      L = i;
      for (int j(i); j < (n); ++j) {
        if (s[j] == s[j - i]) {
          ++Z[i];
        } else
          break;
      }
      R = L + Z[i] - 1;
    }
  }
  return Z;
}
vector<int> z_function(string s) {
  int n = (int)s.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 && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
string randomString() {
  int n = 10 + rand() % 4;
  string str(n, '-');
  for (int i = 0; i < (n); ++i) str[i] = rand() % 3 + 'a';
  return str;
}
int main() {
  string s;
  cin >> s;
  vector<int> Z = Z_Algorithm(s);
  int n = s.size();
  int bestInner = 0;
  vector<bool> T(n + 1), R(n + 1);
  for (int i = 0; i < (Z.size()); ++i) {
    if (i + Z[i] == n) {
      R[Z[i]] = 1;
      bestInner = max(bestInner, Z[i] - 1);
    } else
      bestInner = max(bestInner, Z[i]);
  }
  int best = 0;
  for (int i = 0; i < (R.size()); ++i)
    if (R[i] && bestInner >= i) best = i;
  if (best) {
    cout << s.substr(0, best) << endl;
  } else {
    cout << "Just a legend" << endl;
  }
  return 0;
}
