public static void main ( String [ ] stp ) throws Exception {
  Scanner scan = new Scanner ( System . in ) ;
  PrintWriter pw = new PrintWriter ( System . out ) ;
  BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ;
  StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ;
  int n = Integer . parseInt ( st . nextToken ( ) ) , m = Integer . parseInt ( st . nextToken ( ) ) , i , j , flat = 0 , floor = 0 ;
  Pair [ ] pair = new Pair [ m ] ;
  TreeSet < Integer > ts = new TreeSet < > ( ) ;
  for ( i = 0 ;
  i < m ;
  i ++ ) {
    st = new StringTokenizer ( br . readLine ( ) ) ;
    pair [ i ] = new Pair ( Integer . parseInt ( st . nextToken ( ) ) , Integer . parseInt ( st . nextToken ( ) ) ) ;
  }
  for ( i = 1 ;
  i <= 100 ;
  i ++ ) {
    boolean flag = true ;
    for ( j = 0 ;
    j < m ;
    j ++ ) {
      floor = ( pair [ j ] . d + i - 1 ) / i ;
      if ( floor != pair [ j ] . g ) {
        flag = false ;
        break ;
      }
    }
    if ( flag ) {
      ts . add ( ( int ) ( ( n + i - 1 ) / i ) ) ;
      if ( ts . size ( ) > 1 ) {
        pw . println ( - 1 ) ;
        pw . flush ( ) ;
        System . exit ( 0 ) ;
      }
    }
  }
  pw . println ( ts . pollFirst ( ) ) ;
  pw . flush ( ) ;
}

public static void main ( String [ ] stp ) throws Exception { Scanner scan = new Scanner ( System . in ) ; PrintWriter pw = new PrintWriter ( System . out ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; int n = Integer . parseInt ( st . nextToken ( ) ) , m = Integer . parseInt ( st . nextToken ( ) ) , i , j , flat = 0 , floor = 0 ; Pair [ ] pair = new Pair [ m ] ; TreeSet < Integer > ts = new TreeSet < > ( ) ; for ( i = 0 ; i < m ; i ++ ) { st = new StringTokenizer ( br . readLine ( ) ) ; pair [ i ] = new Pair ( Integer . parseInt ( st . nextToken ( ) ) , Integer . parseInt ( st . nextToken ( ) ) ) ; } for ( i = 1 ; i <= 100 ; i ++ ) { boolean flag = true ; for ( j = 0 ; j < m ; j ++ ) { floor = ( pair [ j ] . d + i - 1 ) / i ; if ( floor != pair [ j ] . g ) { flag = false ; break ; } } if ( flag ) { ts . add ( ( int ) ( ( n + i - 1 ) / i ) ) ; if ( ts . size ( ) > 1 ) { pw . println ( - 1 ) ; pw . flush ( ) ; System . exit ( 0 ) ; } } } pw . println ( ts . pollFirst ( ) ) ; pw . flush ( ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier))) (throws (type_identifier)) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (object_creation_expression type: (type_identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (array_type element: (type_identifier) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (type_identifier) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments)) arguments: (argument_list)))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (object_creation_expression type: (type_identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (decimal_integer_literal)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (for_statement init: (assignment_expression left: (identifier) right: (decimal_integer_literal)) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)) right: (identifier)) right: (decimal_integer_literal))) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (break_statement))))) (if_statement condition: (parenthesized_expression (identifier)) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (cast_expression type: (integral_type) value: (parenthesized_expression (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))) right: (identifier))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (unary_expression operand: (decimal_integer_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal)))))))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))