Preheat oven to 400 degrees. Grease a 2 litre casserole. Melt margarine; stir in flour and pepper. Add milk and cook until thickened, stirring constantly. Remove from heat and add onion, potatoes, and ham. Pour into prepared pan. Top with cheddar cheese. Bake for 45 minutes.