class Solution {
public:
    int nextGreaterElement(int n) {
       string s=to_string(n);
       next_permutation(s.begin(),s.end());
       if(stoll(s)>n&&stoll(s)<=INT_MAX)
       {
          return stoll(s);
       }
       return -1;

    }
};