Set a custom number of posts on the first page

The pre_get_posts runs before WP_Query has been setup. Some template tags and conditional functions that rely on WP_Query will not work. you will need to work directly with the query vars, which are passed to the pre_get_posts hook as an argument.

See the more information on the following pages: pre_get_posts and using pre_get_posts

Try using the following code.

add_action( 'pre_get_posts', 'sk_change_posts_per_page' );

/**
 * Change Posts Per Page for first page of Posts page
 *
 * @param object $query data
 */
function sk_change_posts_per_page( $query ) {

  if( $query->is_main_query() && ! is_admin() && $query->is_home() && ! $query->is_paged() ) {
    $query->set( 'posts_per_page', '2' );
  }

}