fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, k, a[100005];
  6.  
  7. int main(){
  8. cin >> n >> k;
  9. for (int i = 1; i <= n; i++){
  10. cin >> a[i];
  11. }
  12. int t = a[n];
  13. int z = 0;
  14. for (int i = n-1; i >= 1; i--){
  15. if (a[i]!=t){
  16. z = i;
  17. //cout << t << endl;
  18. break;
  19. }
  20. }
  21. if (k>z) cout << z;
  22. else cout << -1;
  23. return 0;
  24. }
Success #stdin #stdout 0s 15624KB
stdin
3 2
3 1 1
stdout
1