BM Algorithm