#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 3;
int nxt[mxN], vis[mxN];
void get(string s) {
  nxt[0] = -1;
  int i = 0, k = -1, len = s.size();
  while (i < len) {
    if (k == -1 or s[i] == s[k])
      nxt[++i] = ++k;
    else
      k = nxt[k];
  }
}
int main() {
  int t;
  int n, m, i, j, c, a, b, k, cn = 0, sm = 0, mx = INT_MIN, mn = INT_MAX;
  string s, ss, sr;
  bool f = false, ff = true;
  cin >> s;
  get(s);
  nxt[0] = 0;
  n = nxt[s.size()];
  for (i = 0; i < s.size(); i++) vis[nxt[i]] = 1;
  while (n) {
    if (vis[n]) break;
    n = nxt[n];
  }
  if (!n)
    return cout << "Just a legend"
                << "\n",
           0;
  for (i = 0; i < n; i++) cout << s[i];
  return 0;
}
