MinDistance (1st task) simple implementation