protected function filterValidCountry($countries)
    {
        $result = Collection::make($countries)
                            ->filter(function ($country) {
                                try {
                                    $instance = $this->lib->parse($this->number, $country);

                                    return $this->lenient
                                        ? $this->lib->isPossibleNumber($instance, $country)
                                        : $this->lib->isValidNumberForRegion($instance, $country);
                                } catch (libNumberParseException $e) {
                                    return false;
                                }
                            })->first();

        // If we got a new result, return it.
        if ($result) {
            return $result;
        }

        // Last resort: try to detect it from an international number.
        if ($this->numberLooksInternational()) {
            $countries[] = null;
        }

        foreach ($countries as $country) {
            $instance = $this->lib->parse($this->number, $country);

            if ($this->lib->isValidNumber($instance)) {
                return $this->lib->getRegionCodeForNumber($instance);
            }
        }

        if ($countries = array_filter($countries)) {
            throw NumberParseException::countryMismatch($this->number, $countries);
        }

        throw NumberParseException::countryRequired($this->number);
    }