def count_primes(limit):
    """Count prime numbers less than or equal to limit."""
    if limit < 2:
        return 0

    # Sieve of Eratosthenes
    is_prime = [True] * (limit + 1)
    is_prime[0] = is_prime[1] = False

    for i in range(2, int(limit**0.5) + 1):
        if is_prime[i]:
            for j in range(i * i, limit + 1, i):
                is_prime[j] = False

    return sum(is_prime)


if __name__ == "__main__":
    import sys
    if len(sys.argv) > 1:
        limit = int(sys.argv[1])
        print(count_primes(limit))
