var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( '\n' ).map( Number );
  var n = data[0];
  var Ri = Number.POSITIVE_INFINITY;
  var profit = Number.NEGATIVE_INFINITY;
  var d = Number.NEGATIVE_INFINITY;
  for( var i=1; i<=n; i++ ) {
    d = data[i]-Ri;
    if( profit < d ) {
      profit = d;
    }
    if( data[i] < Ri ) {
      Ri = data[i];
    }
  }
  
  console.log( profit );
});