// https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_6_B
#include <iostream>
#include <queue>
#include <limits>
template <typename T>
constexpr T INF() { return std::numeric_limits<T>::max() / 16; }
#include <vector>
template <typename Cap, typename Cost>
struct CostFlow
{
    CostFlow(const std::size_t v) : V(v), edge(v) {}
    void addEdge(const std::size_t from, const std::size_t to, const Cap cap, const Cost cost) { edge[from].push_back({to, edge[to].size(), cap, cost, false}), edge[to].push_back({from, edge[from].size() - 1, 0, -cost, true}); }
    struct Edge
    {
        std::size_t to, rev;
        Cap cap;
        Cost cost;
        const bool isrev;
    };
    const std::size_t V;
    std::vector<std::vector<Edge>> edge;
};
template <typename T, template <typename, typename, typename> class PotFunc, typename Cap, typename Cost>
std::pair<bool, T> PrimalDual(CostFlow<Cap, Cost>& cflow, const std::size_t s, const std::size_t t, Cap f)
{
    const std::size_t V = cflow.V;
    T ans = 0;
    std::vector<T> potential = PotFunc<T, Cap, Cost>()(cflow, s);
    std::vector<T> dist(V, INF<T>());
    using P = std::pair<T, std::size_t>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> Q;
    std::vector<std::size_t> prev_v(V), prev_e(V);
    while (f > 0) {
        std::fill(dist.begin(), dist.end(), INF<T>());
        dist[s] = 0, Q.push({0, s});
        while (not Q.empty()) {
            const T cost = Q.top().first;
            const std::size_t v = Q.top().second;
            Q.pop();
            if (dist[v] < cost) { continue; }
            for (std::size_t i = 0; i < cflow.edge[v].size(); i++) {
                const auto& e = cflow.edge[v][i];
                const T pd = potential[v] - potential[e.to];
                if (e.cap == 0 or dist[e.to] <= dist[v] + e.cost + pd) { continue; }
                dist[e.to] = dist[v] + e.cost + pd, prev_v[e.to] = v, prev_e[e.to] = i;
                Q.push({dist[e.to], e.to});
            }
        }
        if (dist[t] == INF<T>()) { return {false, ans}; }
        for (std::size_t v = 0; v < V; v++) { potential[v] += dist[v]; }
        Cap d = f;
        for (std::size_t v = t; v != s; v = prev_v[v]) {
            const auto& e = cflow.edge[prev_v[v]][prev_e[v]];
            d = std::min(d, e.cap);
        }
        f -= d, ans += (T)d * potential[t];
        for (std::size_t v = t; v != s; v = prev_v[v]) {
            auto& e = cflow.edge[prev_v[v]][prev_e[v]];
            e.cap -= d, cflow.edge[v][e.rev].cap += d;
        }
    }
    return {true, ans};
}
template <typename T, typename Cap, typename Cost>
struct PotNone
{
    std::vector<T> operator()(const CostFlow<Cap, Cost>& cflow, const std::size_t) const { return std::vector<T>(cflow.V, 0); }
};
int main()
{
    std::size_t V, E, F;
    std::cin >> V >> E >> F;
    CostFlow<std::size_t, std::size_t> cflow(V);
    for (std::size_t i = 0; i < E; i++) {
        std::size_t u, v, c, d;
        std::cin >> u >> v >> c >> d;
        cflow.addEdge(u, v, c, d);
    }
    const auto ans = PrimalDual<int, PotNone>(cflow, 0, V - 1, F);
    std::cout << (ans.first ? ans.second : -1) << std::endl;
    return 0;
}


Measured memory_bytes: 3236