#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-10;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };


using namespace std;


class MinimumCostFlow {
    struct Edge {
        const int to;         // 行き先のノードid
        int flow;             // 流量
        const int cap;        // 容量
        const int cost;       // コスト
        const int rev;        // 逆辺のノードid
        const bool is_rev;    // 逆辺かどうか
        Edge(int to, int flow, int cap, int cost, int rev, bool is_rev) : to(to), flow(flow), cost(cost), cap(cap), rev(rev), is_rev(is_rev) {
            assert(this->cap >= 0);
        }
    };

    const int num_node;     // 頂点数
    vector<vector<Edge>> graph; // グラフの隣接リスト表現

public:
    MinimumCostFlow(int num_node) : num_node(num_node) {
        graph.resize(num_node);
    }

    // fromからtoへ向かう容量cap、コストcostの辺をグラフに追加する
    void add_edge(int from, int to, int cap, int cost) {
        graph.at(from).emplace_back(Edge(to, 0, cap, cost, graph[to].size(), false));
        graph.at(to).emplace_back(Edge(from, cap, cap, -cost, graph[from].size() - 1, true));
    }

    // sからtへの流量fの最小費用流を求める
    // 流せない場合は-1を返す
    int min_cost_flow(int source, int sink, int f) {
        int res = 0;

        vector<int> prev_v(num_node, 0), prev_e(num_node, 0); // 直前の頂点と辺のidx
        vector<int> potential(num_node, 0);                   // ポテンシャル

        // 負の辺がある場合、ポテンシャルをベルマンフォードで求めておく
        if (0 < f) {
            potential.assign(num_node, INT_MAX);
            potential[source] = 0;
            while (true) {
                bool updated = false;
                for (int v = 0; v < num_node; ++v) {
                    for (auto &e : graph.at(v)) {
                        if (e.cap - e.flow > 0) {
                            if (potential[v] == INT_MAX) {
                                continue;
                            }
                            if (potential[e.to] > potential[v] + e.cost) {
                                potential[e.to] = potential[v] + e.cost;
                                updated = true;
                            }
                        }
                    }
                }
                if (not updated) {
                    break;
                }
            }
        }

        while (f > 0) {
            // ダイクストラ法を用いてポテンシャルを更新する
            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > que;
            vector<int> distance(num_node, INT_MAX);      // 最短距離

            distance[source] = 0;
            que.push(make_pair(0, source));
            while (not que.empty()) {
                pair<int, int> p = que.top(); // firstは最短距離、secondは頂点の番号
                que.pop();
                int v = p.second;
                if (distance[v] < p.first) {
                    continue;
                }
                for (int i = 0; i < graph[v].size(); i++) {
                    Edge &e = graph[v][i];
                    if (e.cap - e.flow > 0 and distance[e.to] > distance[v] + e.cost + potential[v] - potential[e.to]) {
                        distance[e.to] = distance[v] + e.cost + potential[v] - potential[e.to];
                        prev_v[e.to] = v;
                        prev_e[e.to] = i;
                        que.push(make_pair(distance[e.to], e.to));
                    }
                }
            }

            // これ以上流せない
            if (distance[sink] == INT_MAX) {
                return -1;
            }
            for (int v = 0; v < num_node; ++v) {
                potential[v] += distance[v];
            }

            // source-sink間で流せる量を求める
            int d = f;
            for (int v = sink; v != source; v = prev_v[v]) {
                auto &e = graph[prev_v[v]][prev_e[v]];
                d = min(d, e.cap - e.flow);
            }

            f -= d;
            res += d * potential[sink];
            for (int v = sink; v != source; v = prev_v[v]) {
                Edge &e = graph[prev_v[v]][prev_e[v]];
                e.flow += d;
                graph[v][e.rev].flow -= d;
            }
        }

        return res;
    }
};

int main(void) {
    int V, E, F;
    cin >> V >> E >> F;

    MinimumCostFlow mcf(V);
    FOR(i, 0, E) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        mcf.add_edge(u, v, c, d);
    }

    print(mcf.min_cost_flow(0, V - 1, F));

}


Measured memory_bytes: 3300