#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define MAX_N 107
class MinCostFlow {
  static const ll inf = 1e18;
  struct Edge {
    int to, cap, cost;
    size_t rev;
  };

  vector<Edge> g[MAX_N];
  int h[MAX_N];
  int prv_v[MAX_N], prv_e[MAX_N];
  ll dist[MAX_N];
  int n;

public:
  MinCostFlow(int n) : n(n) {}

  void add_edge(int fr, int to, int cap, int cost) {
    g[fr].emplace_back(Edge{to, cap, cost, g[to].size()});
    g[to].emplace_back(Edge{fr, 0, -cost, g[fr].size()-1});
  }

  ll flow(int s, int t, ll f) {
    ll res = 0;
    for(int i=0; i<n; ++i) h[i] = prv_v[i] = prv_e[i] = 0;

    while(f) {
      for(int i=0; i<n; ++i) dist[i] = inf;
      dist[s] = 0;

      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0, s));
      while(!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;

        for(int i=0; i<g[v].size(); ++i) {
          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];
            prv_v[e.to] = v; prv_e[e.to] = i;
            que.push(P(dist[e.to], e.to));
          }
        }
      }
      if(dist[t] == inf) {
        return -1;
      }
      for(int i=0; i<n; ++i) h[i] += dist[i];

      ll d = f;
      int v = t;
      while(v != s) {
        d = min(d, (ll) g[prv_v[v]][prv_e[v]].cap);
        v = prv_v[v];
      }
      f -= d;
      res += d * h[t];
      v = t;
      while(v != s) {
        Edge &e = g[prv_v[v]][prv_e[v]];
        e.cap -= d;
        g[v][e.rev].cap += d;
        v = prv_v[v];
      }
    }
    return res;
  }
};

int n, m, f;

int main() {
  cin >> n >> m >> f;
  MinCostFlow mct(n);
  rep(i, m) {
    int u, v, c, d; cin >> u >> v >> c >> d;
    mct.add_edge(u, v, c, d);
  }
  cout << mct.flow(0, n-1, f) << endl;
  return 0;
}


Measured memory_bytes: 3160