public static void main ( String [ ] args ) {
  Scanner sc = new Scanner ( System . in ) ;
  int n = sc . nextInt ( ) ;
  int m = sc . nextInt ( ) ;
  Edge [ ] edge = new Edge [ m ] ;
  for ( int i = 0 ;
  i < m ;
  i ++ ) {
    int a = sc . nextInt ( ) - 1 ;
    int b = sc . nextInt ( ) - 1 ;
    long c = sc . nextLong ( ) ;
    edge [ i ] = new Edge ( a , b , - c ) ;
  }
  long [ ] dist = new long [ n ] ;
  Arrays . fill ( dist , Long . MAX_VALUE ) ;
  dist [ 0 ] = 0 ;
  boolean flag = true ;
  int cnt = 0 ;
  long ans = 0 ;
  while ( flag ) {
    flag = false ;
    for ( int i = 0 ;
    i < m ;
    i ++ ) {
      if ( dist [ edge [ i ] . from ] != Long . MAX_VALUE && dist [ edge [ i ] . to ] > dist [ edge [ i ] . from ] + edge [ i ] . cost ) {
        flag = true ;
        dist [ edge [ i ] . to ] = dist [ edge [ i ] . from ] + edge [ i ] . cost ;
      }
    }
    if ( cnt == n ) {
      ans = - dist [ n - 1 ] ;
    }
    if ( cnt == 2 * n ) {
      if ( ans < - dist [ n - 1 ] ) {
        System . out . println ( "inf" ) ;
        return ;
      }
      break ;
    }
    cnt ++ ;
  }
  System . out . println ( - dist [ n - 1 ] ) ;
}

public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int m = sc . nextInt ( ) ; Edge [ ] edge = new Edge [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { int a = sc . nextInt ( ) - 1 ; int b = sc . nextInt ( ) - 1 ; long c = sc . nextLong ( ) ; edge [ i ] = new Edge ( a , b , - c ) ; } long [ ] dist = new long [ n ] ; Arrays . fill ( dist , Long . MAX_VALUE ) ; dist [ 0 ] = 0 ; boolean flag = true ; int cnt = 0 ; long ans = 0 ; while ( flag ) { flag = false ; for ( int i = 0 ; i < m ; i ++ ) { if ( dist [ edge [ i ] . from ] != Long . MAX_VALUE && dist [ edge [ i ] . to ] > dist [ edge [ i ] . from ] + edge [ i ] . cost ) { flag = true ; dist [ edge [ i ] . to ] = dist [ edge [ i ] . from ] + edge [ i ] . cost ; } } if ( cnt == n ) { ans = - dist [ n - 1 ] ; } if ( cnt == 2 * n ) { if ( ans < - dist [ n - 1 ] ) { System . out . println ( " inf " ) ; return ; } break ; } cnt ++ ; } System . out . println ( - dist [ n - 1 ] ) ; }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (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: (integral_type) declarator: (variable_declarator name: (identifier) value: (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)))) (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))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (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 (identifier) (identifier) (unary_expression operand: (identifier)))))))) (local_variable_declaration type: (array_type element: (integral_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (integral_type) dimensions: (dimensions_expr (identifier))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier) (field_access object: (identifier) field: (identifier))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (decimal_integer_literal))) (local_variable_declaration type: (boolean_type) declarator: (variable_declarator name: (identifier) value: (true))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (while_statement condition: (parenthesized_expression (identifier)) body: (block (expression_statement (assignment_expression left: (identifier) right: (false))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (array_access array: (identifier) index: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))) right: (field_access object: (identifier) field: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier)))))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (true))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))) right: (binary_expression left: (array_access array: (identifier) index: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))) right: (field_access object: (array_access array: (identifier) index: (identifier)) field: (identifier))))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (unary_expression operand: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier)))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (break_statement))) (expression_statement (update_expression (identifier))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (unary_expression operand: (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal)))))))))