#include <bits/stdc++.h>
using namespace std;
char s[1000006];
int pre[1000006];
int vis[1000005];
void prefix(int l) {
  pre[0] = -1;
  for (int i = 1, j = -1; i <= l; i++) {
    while (j != -1 && s[j] != s[i - 1]) j = pre[j];
    pre[i] = ++j;
  }
}
int main() {
  memset(vis, 0, sizeof(vis));
  cin >> s;
  int l = strlen(s);
  prefix(l);
  int j = l;
  while (j > 0) {
    vis[pre[j]] = 1;
    j = pre[j];
  }
  vis[0] = 0;
  int found = 0;
  int ans = 0;
  for (int i = 2; i < l; i++) {
    if (vis[pre[i]] && pre[i] > ans) {
      found = 1;
      ans = pre[i];
    }
  }
  if (found)
    cout << s + l - ans;
  else
    cout << "Just a legend";
  return 0;
}
