Self-consistent pair potential in superconductors. I. The superconductor-insulator boundary nearTc