#include <bits/stdc++.h>

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double PI = atan(1.0) * 4.0;
// const int MOD = 998244353;
const ll LINF = 9e18;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

struct edge {
    ll to, cap, cost, rev;
};

// dijkstra
struct Mincostflow {
    vector<vector<edge>> G;
    VL h, dist, prev, pree;
    ll N;

    Mincostflow(ll size) : N(size) { init(size); };

    void init(ll size) {
        G.resize(N);
        prev.resize(N);
        pree.resize(N);
    }

    void add_edge(ll from, ll to, ll cap, ll cost) {
        G[from].push_back({to, cap, cost, (ll)G[to].size()});
        G[to].push_back({from, 0, -cost, (ll)G[from].size() - 1});
    }

    ll min_cost_flow(ll s, ll t, ll f) {
        ll res = 0;
        h.assign(N, 0);
        while(f > 0) {
            PQG<PL> pq;
            dist.assign(N, LINF);
            dist[s] = 0;
            pq.emplace(dist[s], s);
            while(!pq.empty()) {
                PL p = pq.top();
                pq.pop();
                ll v = p.se;
                REP(i, G[v].size()) {
                    edge &e = G[v][i];
                    if(e.cap > 0 &&
                       dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                        dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                        prev[e.to] = v;
                        pree[e.to] = i;
                        pq.emplace(dist[e.to], e.to);
                    }
                }
            }
            if(dist[t] == LINF) return -1;
            REP(v, N) h[v] += dist[v];
            ll d = f;
            for(int v = t; v != s; v = prev[v]) {
                d = min(d, G[prev[v]][pree[v]].cap);
            }
            f -= d;
            res += d * h[t];
            for(int v = t; v != s; v = prev[v]) {
                edge &e = G[prev[v]][pree[v]];
                e.cap -= d;
                G[v][e.rev].cap += d;
            }
        }
        return res;
    }
};

signed main() {
    LCIN(V, E, F);
    Mincostflow mcf(V);
    REP(i, E) {
        LCIN(u, v, c, d);
        mcf.add_edge(u, v, c, d);
    }
    cout << mcf.min_cost_flow(0, V - 1, F) << "\n";
}



Measured memory_bytes: 3280