#include <bits/stdc++.h>
using namespace std;
string txt;
int z[2000009];
void zFunc(string s) {
  int n = (int)s.size();
  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;
  }
}
string s;
set<int> ss;
int main() {
  cin >> s;
  zFunc(s);
  int n = s.size();
  int ans = 0;
  for (int i = 01; i < n; i++) {
    if (i + z[i] == n) {
      if (i <= z[i]) {
        int cur = z[i] - i;
        ans = max(ans, cur);
      } else
        ss.insert(z[i]);
    }
  }
  if (ss.size())
    for (int i = 1; i < n; i++) {
      if (z[i] + i != n) {
        if (z[i] >= *ss.begin()) ans = max(ans, *(--ss.upper_bound(z[i])));
      }
    }
  if (!ans)
    cout << "Just a legend\n";
  else
    cout << s.substr(0, ans) << '\n';
}
