import java.util.*
import javax.security.auth.login.AccountLockedException

class Feed(val x:Int){
    private val mCats: Stack<Cats> = Stack()
    var count:Int = 0
        private set
    val cats:Iterable<Cats> = mCats
    fun addCats(cats:Iterable<Cats>):Unit {
        mCats.addAll(cats)
        count += cats.sumBy { it.size }
    }
    fun addCats(cats:Cats):Unit {
        mCats.add(cats)
        count += cats.size
    }
}
class Cats(val x:Int, val size:Int)
fun allocationCats(left:Feed, cats:Iterable<Cats>, right:Feed):Unit {
    val mid = right.x + left.x
    left.addCats(cats.filter{it.x * 2 <= mid})
    right.addCats(cats.filter{it.x * 2 > mid})
}
fun main(args:Array<String>):Unit {
    while(true){
        val (n,m) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && m == 0) return
        val cats = Array(n){
            val (x, _, c) = readLine()!!.trim().split(' ').map(String::toInt)
            Cats(x, c)
        }
        val feeds = LinkedList<Feed>()
        repeat(m){feeds.addLast(Feed(readLine()!!.trim().toInt()))}
        feeds.sortBy(Feed::x)
        val feedArray = feeds.toTypedArray()
        feedArray[0].addCats(cats.filter{it.x < feedArray[0].x})
        for (i in 1 until m) {
            allocationCats(feedArray[i - 1], cats.filter{it.x in feedArray[i - 1].x until feedArray[i].x}, feedArray[i])
        }
        feedArray.last().addCats(cats.filter{feedArray.last().x <= it.x})
        var minMax = Int.MAX_VALUE
        repeat(m - 2){
            val max = feeds.maxBy(Feed::count)!!
            if (minMax > max.count) minMax = max.count
            val idx = feeds.indexOf(max)
            feeds.removeAt(idx)
            if (idx == feeds.size)
                feeds[idx - 1].addCats(max.cats)
            else if (idx == 0)
                feeds[0].addCats(max.cats)
            else
                allocationCats(feeds[idx - 1], max.cats, feeds[idx])
        }
        if (minMax > feeds.maxBy(Feed::count)!!.count) minMax = feeds.maxBy(Feed::count)!!.count
        println(minMax)
    }
}
