const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

let count = 0;
var numberOfStudents = 0;
var totalStudents = 0;

while(count < lines.length) {
	

	if(count%2 == 0) {
		numberOfStudents = +lines[count];
		if (numberOfStudents==0) {
			break;
		} else if(numberOfStudents>1000) {
			console.log('Number of students must not be greater than 1,000.');
			break;
		} else if(numberOfStudents<2) {
			console.log('Number of students must not be less than 2.');
			break;
		} else {
			totalStudents += numberOfStudents;
			if(totalStudents>50000) {
				break;
			}
		}
	} else {
		let scoresString = lines[count].split(' ');
		
		if(scoresString.length != numberOfStudents) {
			console.log(`Number of students is not equal to number of scores at line ${count+1}`);
			break;
		} else {
		let scores = scoresString.map(score => +score);
			var leastDiff = null;
			var currentDiff;
			for (let i = scores.length - 1; i >= 0; i--) {
				if(isNotGreaterThanMillion(scores[i])) {
					break;
				} else {
					for(j=i; j>=0; j--) {
					if(i) {
						if (leastDiff != null) {
							currentDiff = Math.abs(scores[i] - scores[j-1]);
						if (currentDiff < leastDiff) {
							leastDiff = currentDiff;
						}
					} else {
						leastDiff = Math.abs(scores[i] - scores[j-1]);
					}

				}		
					}
				}



			}
			console.log(leastDiff);
		}
	}

count++;

}

function isNotGreaterThanMillion(number) {
	if (number>1000000) {
		return true;
	}
}
