#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const int INF = 2e9;
const long long LINF = 1e18;
template <class T>
const T sqr(const T &x) {
  return x * x;
}
template <class T>
const T &min(const T &a, const T &b, const T &c) {
  return min(min(a, b), c);
}
template <class T>
const T &max(const T &a, const T &b, const T &c) {
  return max(max(a, b), c);
}
struct DbgStream {
  template <class T>
  DbgStream &operator<<(const T &x) {
    return *this;
  }
} z_dbg;
struct SingleHash {
  vector<int> suf, b;
  int mod;
  SingleHash(string s, int base = 153, int _mod = 1000000009) {
    int n = s.length();
    suf.assign(n + 1, 0);
    b.assign(n + 1, 0);
    b[0] = 1;
    b[1] = base;
    mod = _mod;
    for (int i = n - 1; i >= 0; --i) {
      suf[i] = (s[i] + (long long)suf[i + 1] * b[1]) % mod;
    }
    for (int i = 2; i <= n; ++i) {
      b[i] = (long long)b[i - 1] * b[1] % mod;
    }
  }
  int substr(int l, int r) const {
    long long v = suf[l] - (long long)suf[r + 1] * b[r - l + 1];
    v %= mod;
    v += mod;
    v %= mod;
    return v;
  }
};
bool check(int m, int n, const SingleHash &h) {
  int pref = h.substr(0, m - 1);
  for (int i = 1; i + m < n; ++i) {
    if (pref == h.substr(i, i + m - 1)) {
      return 1;
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  string s;
  cin >> s;
  SingleHash h(s);
  n = s.length();
  vector<int> lens;
  lens.reserve(n);
  for (int i = 1; i < n; ++i) {
    if (h.substr(0, i - 1) == h.substr(n - i, n - 1)) {
      lens.push_back(i);
    }
  }
  int l = 0, r = lens.size();
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(lens[m], n, h)) {
      l = m;
    } else {
      r = m;
    }
  }
  if (lens.empty() || !check(lens[l], n, h)) {
    cout << "Just a legend\n";
    return 0;
  }
  for (int i = 0; i < lens[l]; ++i) {
    cout << s[i];
  }
  cout << "\n";
  return 0;
}
