#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const int INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
class PrimalDual{
    private:
        struct edge{
            int to,cap,cost,rev;
        };
        int siz;
        vector<vector<edge>> edges;
        vector<int> potential,d;
        vector<int> prevv,preve;
    public:
        PrimalDual(int n):edges(n){
            prevv.resize(n);
            preve.resize(n);
            siz = n;
        }
        void add_edge(int from,int to,int cap,int cost){
            edges[from].push_back((edge{to,cap,cost,(int)edges[to].size()}));
            edges[to].push_back((edge{from,0,-cost,(int)edges[from].size()-1}));
        }
        int min_cost_flow(int s,int t,int f){
            int res = 0;
            potential.assign(siz,0);
            while(f > 0){
                priority_queue<P,vector<P>,greater<P>> q;
                d.assign(siz,INF);
                q.push(P(0,s));
                d[s] = 0;
                while(!q.empty()){
                    P p = q.top();q.pop();
                    int v = p.second;
                    if (d[v] < p.first) continue;
                    rep(i,edges[v].size()){
                        edge &e = edges[v][i];
                        if (e.cap > 0 && chmin(d[e.to],d[v]+e.cost+potential[v]-potential[e.to])){
                            prevv[e.to] = v;
                            preve[e.to] = i;
                            q.push(P(d[e.to],e.to));
                        }
                    }
                }
                if (d[t] == INF) return -1;
                rep(v,siz) potential[v] += d[v];
                int k = f;
                for(int v = t;v != s;v = prevv[v]){
                    chmin(k,edges[prevv[v]][preve[v]].cap);
                }
                f -= k;
                res += k*potential[t];
                for(int v = t;v != s;v = prevv[v]){
                    edge &e = edges[prevv[v]][preve[v]];
                    e.cap -= k;
                    edges[v][e.rev].cap += k;
                }
            }
            return res;
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V,E,F;
    int u,v,c,d;
    cin >> V >> E >> F;
    PrimalDual g(V);
    rep(i,E){
        cin >> u >> v >> c >> d;
        g.add_edge(u,v,c,d);
    }
    PRINT(g.min_cost_flow(0,V-1,F));
}



Measured memory_bytes: 3260