﻿namespace topCoder
{
	using System;
	using System.Collections.Generic;

	class p1
	{
		public void foo()
		{
			string[] sp = Console.ReadLine().Split(' ');
			int n = int.Parse(sp[0]);
			int m = int.Parse(sp[1]);

			Console.WriteLine(bar(n, m));
		}
		private int bar(int n, int m)
		{
			int l = n / 2 + (n%2 != 0 ? 1 : 0);
			int h = n;

			while (l <= h)
			{
				if (l % m == 0)
					return l;
				l++;
			}
			return -1;
		}
	}
}
