Reorder list elements (by code, not mouse)

Reorder list elements (by code, not mouse)

I have a list with values and the order from start is a bit random and differs from time to time:

  1. <ul>
  2.       <li>2</li>
  3.       <li>10</li>
  4.       <li>5</li>
  5.       <li>7</li>
  6.       <li>6</li>
  7.       <li>8</li>
  8.       <li>9</li>
  9.       <li>4</li>
  10.       <li>1</li>
  11.       <li>3</li>
  12. </ul>

How do I reorder the list so that 1, 3, 6 and 7 always ends up first?
Also the order of the rest of the elements needs to be preserved. So the result would be:

  1. <ul>
  2.    <li>1</li>
  3.    <li>3</li>
  4.    <li>6</li>
  5.    <li>7</li>
  6.    <li>2</li>
  7.    <li>10</li>
  8.    <li>5</li>
  9.    <li>8</li>
  10.    <li>9</li>
  11.    <li>4</li>
  12. </ul>