#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long infinity = 1000000000000000000;
bool do_debug = false;
template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto element : v) {
    os << element << " ";
  }
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& v) {
  if (v.size() == 0) {
    os << "empty set\n";
    return os;
  }
  auto endit = v.end();
  endit--;
  os << "[";
  for (auto it = v.begin(); it != v.end(); it++) {
    os << *it;
    if (it != endit) {
      os << ", ";
    }
  }
  os << "]";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, multiset<T>& v) {
  if (v.size() == 0) {
    os << "empty multiset\n";
    return os;
  }
  auto endit = v.end();
  endit--;
  os << "[";
  for (auto it = v.begin(); it != v.end(); it++) {
    os << *it;
    if (it != endit) {
      os << ", ";
    }
  }
  os << "]";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, map<T, S>& v) {
  if (v.size() == 0) {
    os << "empty map\n";
    return os;
  }
  auto endit = v.end();
  endit--;
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++) {
    os << "(" << (*it).first << " : " << (*it).second << ")";
    if (it != endit) {
      os << ", ";
    }
  }
  os << "}";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& v) {
  for (auto& subv : v) {
    for (auto& e : subv) {
      os << e << " ";
    }
    os << "\n";
  }
  return os;
}
void gen_z(vector<int>& z, string s, int len) {
  int l = 0, r = 0;
  for (int i = 1; i < len; i++) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
    }
    while (i + z[i] < len && s[z[i]] == s[i + z[i]]) {
      z[i]++;
    }
    if (z[i] + i - 1 > r) {
      l = i;
      r = z[i] + i - 1;
    }
  }
}
void solve() {
  string s;
  cin >> s;
  int len = s.length();
  vector<int> z(len, 0);
  multiset<int> sett;
  vector<int> cv(len, 0);
  gen_z(z, s, len);
  for (int i = 1; i < len - 1; i++) {
    int contr = z[i];
    if (i + contr - 1 == len - 1) {
      contr--;
    }
    if (contr) {
      sett.insert(contr);
    }
    cv[i] = contr;
  }
  int ans_i = -1, ans_l = 0;
  for (int i = len - 1; i >= 1; i--) {
    if (cv[i]) {
      sett.erase(sett.find(cv[i]));
    }
    if (!sett.size()) {
      break;
    }
    if (*sett.rbegin() >= z[i] && i + z[i] - 1 == len - 1) {
      if (z[i] > ans_l) {
        ans_l = z[i];
        ans_i = i;
      }
    }
  }
  if (ans_i != -1) {
    for (int i = ans_i; i < ans_i + ans_l; i++) {
      cout << s[i];
    }
    cout << "\n";
  } else {
    cout << "Just a legend";
    cout << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q = 1;
  while (q-- > 0) {
    solve();
  }
  return 0;
}
