#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;

class Edge{
public:
    Int from, to, rev;
    Int cost, lim;
    Edge(Int from, Int to, Int cost, Int lim = -1, Int rev = -1):
        from(from),to(to),cost(cost),lim(lim),rev(rev){}
};


class Graph{
public:
    Int n;
    Int m;
    vector<vector<Edge>> edge;
    Graph(Int n = 0):n(n),m(0){
        edge = vector<vector<Edge>>(n);
    }
    void add_edge(Int from, Int to, Int cost = 1, Int lim = -1)
        {
            if(lim == -1){
                edge[from].push_back(Edge(from, to, cost));
                return;
            }
            edge[from].push_back(Edge(from, to, cost, lim, edge[to].size()));
            edge[to].push_back(Edge(to, from, -cost, 0, edge[from].size() - 1));
        }
};



class MinCostFlow{
public:
    priority_queue<P, vector<P>, greater<P> > pq;
    vector<Int> dist;
    vector<Int> before;
    vector<Int> index;
    vector<Int> potential;
    MinCostFlow(){}
    
    void Dijkstra(Graph &g, Int s){
        fill(dist.begin(), dist.end(), INF);
        pq.push(P(0, s));
        dist[s] = 0;

        while(!pq.empty()){
            P tmp = pq.top();pq.pop();
            Int from = tmp.second;
            if(tmp.first > dist[from])continue;
            for(Int i = 0;i < g.edge[from].size();i++){
                auto e = g.edge[from][i];
                auto cost = e.cost + potential[e.from] - potential[e.to];
                if(e.lim == 0)continue;
                if(dist[e.to] <= dist[from] + cost)continue;
                dist[e.to] = dist[from] + cost;
                before[e.to] =from;
                index[e.to] = i;
                pq.push(P(dist[e.to], e.to));
            }
        }
        for(int i = 0;i < g.n;i++){
            dist[i] += potential[i];
            potential[i] = dist[i];
        }
    }

    
    Int mcf(Graph &g, Int s, Int t, Int f){
        Int res = 0;
        dist = vector<Int>(g.n);
        potential = vector<Int>(g.n);
        before = vector<Int>(g.n);
        index = vector<Int>(g.n);
        while(f){
            Dijkstra(g, s);
            Int flow = f;
            for(Int now = t;now != s;){
                Int last = before[now];
                Int ind = index[now];
                auto &e = g.edge[last][ind];
                if(e.lim == 0 || e.to != now)return -1;
                flow = min(flow, e.lim);
                now = last;
            }
            for(Int now = t;now != s;){
                Int last = before[now];
                Int ind = index[now];
                auto &e = g.edge[last][ind];
                e.lim -= flow;
                g.edge[e.to][e.rev].lim += flow;
                res += e.cost * flow;
                now = last;
            }
            f -= flow;
            if(flow==0)return -1;
        }
        return res;
    }
};

int main(){
    Int V, E, F, v, e, f, u, c, d;
    cin >> V >> E >> F;
    Graph g(V);
    for(int i = 0;i < E;i++){
        cin >> u >> v >> c >> d;
        g.add_edge(u, v, d, c);        
    }
    MinCostFlow mcf;
    auto ans = mcf.mcf(g, 0, V-1, F);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3200