public static int findSecondMinimal(int[] array) throws Exception {
		
		if (array.length <= 1) {
			System.out.println("The array should have at least two numbers.");
			throw new Exception();
		}
		
		if (array.length == 2) return Math.max(array[0], array[1]);
		
		int minimal = Math.min(array[0], array[1]);
		int secondMinimal = Math.max(array[0], array[1]);
		boolean equalFlag = (minimal == secondMinimal) ? true : false;
		
		for(int i = 2; i < array.length - 1; i++) {
			
			if (array[i] < minimal) {
				secondMinimal = minimal;
				minimal = array[i];
			} else if (array[i] > minimal && array[i] < secondMinimal) {
				secondMinimal = array[i];
			} else if (array[i] > secondMinimal && equalFlag == true) {
				secondMinimal = array[i];
				equalFlag = false;
			}
		}
		
		return secondMinimal;
	}