public static void main ( String [ ] args ) {
  Scanner scanner = new Scanner ( System . in ) ;
  int N = scanner . nextInt ( ) ;
  int M = scanner . nextInt ( ) ;
  final long INF = - 1_000_000_000_000_000L ;
  long [ ] dist = new long [ N ] ;
  for ( int i = 1 ;
  i < N ;
  i ++ ) dist [ i ] = INF ;
  int [ ] [ ] edges = new int [ M ] [ 2 ] ;
  int [ ] costs = new int [ M ] ;
  for ( int i = 0 ;
  i < M ;
  i ++ ) {
    edges [ i ] = new int [ ] {
      scanner . nextInt ( ) - 1 , scanner . nextInt ( ) - 1 };
      costs [ i ] = scanner . nextInt ( ) ;
    }
    int [ ] prev = new int [ N ] ;
    prev [ 0 ] = - 1 ;
    for ( int i = 0 ;
    i < 2 * N ;
    i ++ ) {
      for ( int j = 0 ;
      j < M ;
      j ++ ) {
        int from = edges [ j ] [ 0 ] ;
        int to = edges [ j ] [ 1 ] ;
        int cost = costs [ j ] ;
        if ( dist [ from ] > INF ) {
          long newValue = dist [ from ] + cost ;
          if ( newValue > dist [ to ] ) {
            dist [ to ] = newValue ;
            prev [ to ] = from ;
          }
        }
      }
    }
    boolean [ ] visited = new boolean [ N ] ;
    int i = N - 1 ;
    while ( i != - 1 ) {
      if ( visited [ i ] ) {
        System . out . println ( "inf" ) ;
        return ;
      }
      visited [ i ] = true ;
      i = prev [ i ] ;
    }
    System . out . println ( dist [ N - 1 ] ) ;
  }
  
public static void main ( String [ ] args ) { Scanner scanner = new Scanner ( System . in ) ; int N = scanner . nextInt ( ) ; int M = scanner . nextInt ( ) ; final long INF = - 1_000_000_000_000_000L ; long [ ] dist = new long [ N ] ; for ( int i = 1 ; i < N ; i ++ ) dist [ i ] = INF ; int [ ] [ ] edges = new int [ M ] [ 2 ] ; int [ ] costs = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { edges [ i ] = new int [ ] { scanner . nextInt ( ) - 1 , scanner . nextInt ( ) - 1 } ; costs [ i ] = scanner . nextInt ( ) ; } int [ ] prev = new int [ N ] ; prev [ 0 ] = - 1 ; for ( int i = 0 ; i < 2 * N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { int from = edges [ j ] [ 0 ] ; int to = edges [ j ] [ 1 ] ; int cost = costs [ j ] ; if ( dist [ from ] > INF ) { long newValue = dist [ from ] + cost ; if ( newValue > dist [ to ] ) { dist [ to ] = newValue ; prev [ to ] = from ; } } } } boolean [ ] visited = new boolean [ N ] ; int i = N - 1 ; while ( i != - 1 ) { if ( visited [ i ] ) { System . out . println ( " inf " ) ; return ; } visited [ i ] = true ; i = prev [ i ] ; } 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 (modifiers) type: (integral_type) declarator: (variable_declarator name: (identifier) value: (unary_expression operand: (decimal_integer_literal)))) (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))))) (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: (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (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)) dimensions: (dimensions_expr (decimal_integer_literal))))) (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))))) (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 (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (array_creation_expression type: (integral_type) dimensions: (dimensions) value: (array_initializer (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)) (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (decimal_integer_literal)))))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))) (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 (assignment_expression left: (array_access array: (identifier) index: (decimal_integer_literal)) right: (unary_expression operand: (decimal_integer_literal)))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (decimal_integer_literal) right: (identifier))) update: (update_expression (identifier)) body: (block (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: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (array_access array: (identifier) index: (identifier)) index: (decimal_integer_literal)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) consequence: (block (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))))))))))) (local_variable_declaration type: (array_type element: (boolean_type) dimensions: (dimensions)) declarator: (variable_declarator name: (identifier) value: (array_creation_expression type: (boolean_type) dimensions: (dimensions_expr (identifier))))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (identifier) right: (decimal_integer_literal)))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (unary_expression operand: (decimal_integer_literal)))) body: (block (if_statement condition: (parenthesized_expression (array_access array: (identifier) index: (identifier))) consequence: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (string_literal)))) (return_statement))) (expression_statement (assignment_expression left: (array_access array: (identifier) index: (identifier)) right: (true))) (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))))) (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (array_access array: (identifier) index: (binary_expression left: (identifier) right: (decimal_integer_literal))))))))