input: from typing import List
  
  def longest_valid_subseq_length(nums: List[int], k: int) -> int:
      """
      Given an integer array nums and a non-negative integer k, a sequence is considered valid if there are at most k indices i in the range [0, seq.length - 2] where seq[i] != seq[i + 1].
  
      Return the longest possible length of a valid subsequence from nums.
  
      Examples:
      >>> nums = [1,2,1,1,3], k = 2
      4
      >>> nums = [1,2,3,4,5,1], k = 0
      2
  
      Constraints:
      1 <= nums.length <= 500
      1 <= nums[i] <= 10^9
      0 <= k <= min(nums.length, 25)
      """
output:     
      max_length = 0
      n = len(nums)
  
      for i in range(n):
          cur_changes = 0
          cur_length = 1
          
          for j in range(i + 1, n):
              if nums[j] != nums[j - 1]:
                  cur_changes += 1
                  
              if cur_changes > k:
                  break
                  
              cur_length += 1
          
          max_length = max(max_length, cur_length)
      
      return max_length
  