808_E. Selling Souvenirs
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.

This morning, as usual, Petya will come to the market. Petya has n different souvenirs to sell; ith souvenir is characterised by its weight wi and cost ci. Petya knows that he might not be able to carry all the souvenirs to the market. So Petya wants to choose a subset of souvenirs such that its total weight is not greater than m, and total cost is maximum possible.

Help Petya to determine maximum possible total cost.

Input

The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market.

Then n lines follow. ith line contains two integers wi and ci (1 ≤ wi ≤ 3, 1 ≤ ci ≤ 109) — the weight and the cost of ith souvenir.

Output

Print one number — maximum possible total cost of souvenirs that Petya can carry to the market.

Examples

Input

1 1
2 1


Output

0


Input

2 2
1 3
2 2


Output

3


Input

4 3
3 10
2 7
2 8
1 1


Output

10
```python
def f():
    n, m = map(int, input().split())
    l = list(tuple(map(int, input().split())) for _ in range(n))
    l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True)
    last, r = [0] * 4, 0
    for i, (w, c) in enumerate(l):
        if m < w:
            break
        m -= w
        r += c
        last[w] = c
    else:
        return r
    if not m:
        return r
    res, tail = [r], (None, [], [], [])
    for w, c in l[i:]:
        tail[w].append(c)
    for w in 1, 2, 3:
        tail[w].append(0)
    _, t1, t2, t3 = tail
    if m == 1:
        res.append(r + t1[0])
        if last[1]:
            res.append(r - last[1] + t2[0])
        if last[2]:
            res.append(r - last[2] + t3[0])
        if last[3]:
            r -= last[3]
            res += (r + sum(t1[:4]), r + sum(t1[:2]) + t2[0], r + sum(t2[:2]))
    else:  # m == 2
        res += (r + sum(t1[:2]), r + t2[0])
        if last[1]:
            res.append(r - last[1] + t3[0])
        if last[2]:
            res.append(r - last[2] + t3[0] + t1[0])
    return max(res)


def main():
    print(f())


if __name__ == '__main__':
    main()

```