#include <bits/stdc++.h>
using namespace std;
bool vis[2 * 1000996];
int idx, len;
struct State {
  int len, link;
  map<char, int> nxtc;
} SA[2 * 1000996];
int NumOcc[2 * 1000996];
char str[1000996];
vector<pair<int, int> > lenState;
class SuffixAutomata {
  int sz, last, fnl;
  void init(int idx) {
    SA[idx].len = 0, SA[idx].link = -1;
    SA[idx].nxtc.clear();
  }
  void traverse(int cur, char *ch, int l) {
    while (*ch && NumOcc[cur] >= 3 && cur < sz) {
      if (vis[cur]) len = l;
      int p = SA[cur].nxtc[*ch];
      cur = p, ++ch, ++l;
    }
  }

 public:
  SuffixAutomata() {
    sz = last = 0;
    init(0);
    lenState.clear();
    ++sz;
  }
  int size() { return sz; }
  void extend(char ch) {
    int p, q, clone, cur = sz++;
    init(cur);
    fnl = cur;
    SA[cur].len = SA[last].len + 1;
    NumOcc[cur] = 1;
    lenState.push_back(make_pair(SA[cur].len, cur));
    for (p = last; p != -1 && SA[p].nxtc.count(ch) == 0; p = SA[p].link)
      SA[p].nxtc[ch] = cur;
    if (p == -1)
      SA[cur].link = 0;
    else {
      q = SA[p].nxtc[ch];
      if (SA[p].len + 1 == SA[q].len)
        SA[cur].link = q;
      else {
        clone = sz++;
        init(clone);
        SA[clone] = SA[q];
        SA[clone].len = SA[p].len + 1;
        for (; p != -1 && SA[p].nxtc[ch] == q; p = SA[p].link)
          SA[p].nxtc[ch] = clone;
        SA[cur].link = SA[q].link = clone;
        NumOcc[clone] = 0;
        lenState.push_back(make_pair(SA[clone].len, clone));
      }
    }
    last = cur;
  }
  void traverse(char *str) { traverse(0, str, 0); }
  void numOcc() {
    int i, p, q;
    sort(lenState.begin(), lenState.end());
    for (i = lenState.size() - 1; i >= 0; --i) {
      q = lenState[i].second;
      p = SA[q].link;
      NumOcc[p] += NumOcc[q];
    }
  }
  void crawl() {
    int cur = fnl;
    memset(vis, false, sizeof(vis));
    while (cur > 0) {
      vis[cur] = true;
      cur = SA[cur].link;
    }
  }
};
int main() {
  int i;
  while (scanf("%s", str) != EOF) {
    SuffixAutomata sa;
    for (i = 0; str[i]; ++i) sa.extend(str[i]);
    sa.numOcc();
    sa.crawl();
    len = -1;
    sa.traverse(str);
    if (len <= 0)
      puts("Just a legend");
    else {
      str[len] = 0;
      puts(str);
    }
  }
  return 0;
}
