#include using namespace std; #define ll long long #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define v(t) vector #define pb(e) .push_back(e) #define mp(a,b) .make_pair(a,b) #define fe(e,a) for(auto e : a) #define rang(a) a.begin(), a.end() int main() { fast; #ifdef ONLINE_JUDGE freopen("kstring.in", "r", stdin); freopen("kstring.out", "w", stdout); #endif string s; cin >> s; int k,n = s.length(); cin >> k; if(n%k!=0) {cout << -1 << "\n"; return 0;} // sort(rang(s)); map un; for(auto c : s) { un.count(c)<1 ? un[c]=1 : un[c]++; } int c= 0; string r=""; for(auto p : un) { if(c==n/k) break; if(p.second % k != 0) {cout << -1 << "\n"; return 0;} r+=p.first; c++; } string f; int tys = (n/k)/r.length(); while (tys--) { f+=r; } cout << f << "\n"; }