#include<bits/stdc++.h>
using namespace std;
void dfs(int i,vector<int>k[],long int&c,bool v[]){
    if(v[i]){
        return;
    }
    v[i]=true;
    c++;
    for(auto &x: k[i]){
        dfs(x,k,c,v);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,a,b;
    cin>>n>>q;
    vector<int>adj[10000];
    for(int i=0;i<q;i++){
        cin>>a>>b;
        adj[a-1].push_back(b-1);
    }
    long int s=0;
    long int c=0;
    for(int i=0;i<n;i++){
        c=0;
        bool visited[n+1]={false};
        dfs(i,adj,c,visited);
        s+=c;
    }
    cout<<s;
}
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define print(a)          \
    for (auto x : a)      \
        cout << x << " "; \
    cout << endl
#define print_upto(a, n)        \
    for (ll i = 1; i <= n; i++) \
        cout << a[i] << " ";    \
    cout << endl
#define take(a, n)              \
    for (ll i = 1; i <= n; i++) \
        cin >> a[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x, y) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << "\n"
#define watch3(x, y, z) cout << (#x) << " is " << (x) << " and " << (#y) << " is " << (y) << " and " << (#z) << " is " << (z) << "\n"

void my_debugger(string s, int LINE_NUM)
{
    cerr << endl;
}
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
    if (s.back() != ',')
    {
        s += ',';
        cerr << "LINE(" << LINE_NUM << "): ";
    }
    int i = s.find(',');
    cerr << s.substr(0, i) << " = " << x;
    s = s.substr(i + 1);
    if (!s.empty())
        cerr << ", ";
    my_debugger(s, LINE_NUM, y...);
}
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(), (c).end()
#define allr(c) (c).rbegin(), (c).rend()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define MOD 1000000007
#define inf 1e17
// cout << fixed << setprecision(15) << ans << nl;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> ppll;

const ll N = 200009;

void solve()
{
    ll n, m, q;
    cin >> n >> m >> q;

    vl vn[n + 5];
    for (ll i = 1; i <= n; i++)
    {
        ll w, v;
        cin >> w >> v;

        vn[i] = {w, v};
    }

    ll x[m + 5];
    for (ll i = 1; i <= m; i++)
    {
        cin >> x[i];
    }

    while (q--)
    {
        ll l, r;
        cin >> l >> r;

        ll vis[n + 5] = {0};
        vl avail;
        for (ll i = 1; i < l; i++)
        {
            avail.pb(x[i]);
        }

        for (ll i = r + 1; i <= m; i++)
        {
            avail.pb(x[i]);
        }

        sort(all(avail));

        ll ans = 0;
        for (ll i = 0; i < avail.size(); i++)
        {
            // watch(i);
            vl temp = {INT_MIN, -1ll}; //value, index
            for (ll j = 1; j <= n; j++)
            {
                if (vis[j] == 1)
                    continue;
                if (avail[i] >= vn[j][0] && temp[0] < vn[j][1])
                {
                    temp[0] = vn[j][1];
                    temp[1] = j;
                }
            }

            if (temp[1] != -1)
            {
                // watch2(temp[0], temp[1]);
                vis[temp[1]] = 1;
                ans += temp[0];
            }
        }

        cout << ans << nl;
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll T = 1;
    // cin >> T;

    while (T--)
    {
        solve();
    }

    return 0;
}
