Terahertz pulse generation by the tilted pulse front technique using an M-shaped optical system