#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 5;
const int maxk = 5e5 + 5;
int n, m, K;
struct data {
  int x, y, first, t, second;
  data(int x = 0, int y = 0, int first = 0, int t = 0, int second = 0)
      : x(x), y(y), first(first), t(t), second(second) {}
} s[maxk];
long long dp[maxn][maxn];
long long sum[maxn][maxn];
vector<pair<int, int> > ab[maxn][maxn];
vector<pair<int, int> > cd[maxn][maxn];
inline void umin(long long &x, long long y) {
  if (x == -1 || x > y) x = y;
}
inline bool check(int x, int y, int t) {
  int dt = (x - 1 + y - 1) - t;
  if (dt < 0 || dt % 4) return 0;
  return 1;
}
void todo(int id, int tg, int x, int y, int t) {
  if (check(x, y, t)) {
    int first = s[id].first;
    sum[x][y] += s[id].second;
    if (tg == 2) {
      if (check(x, y - first, t - 1))
        ab[x][y].push_back(pair<int, int>(first, s[id].second));
      if (check(x - first, y, t - 2))
        cd[x][y].push_back(pair<int, int>(first, s[id].second));
    }
    if (tg == 3 && check(x, y - first, t - 3))
      ab[x][y].push_back(pair<int, int>(first, s[id].second));
  }
}
void rd(int &x) {
  x = 0;
  char c;
  while (c = getchar(), !isdigit(c))
    ;
  do x = x * 10 + (c ^ 48);
  while (c = getchar(), isdigit(c));
}
int main() {
  scanf("%d%d%d", &n, &m, &K);
  int x, y, first, t, second;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= K; i++) {
    rd(x);
    rd(y);
    rd(first);
    rd(t);
    rd(second);
    ++x;
    ++y;
    s[i] = data(x, y, first, t, second);
    todo(i, 0, x, y, t);
    todo(i, 1, x + first, y - first, t + 1);
    todo(i, 2, x + first, y + 0, t + 2);
    todo(i, 3, x + 0, y + first, t + 3);
  }
  dp[1][1] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (dp[i][j] != -1) {
        long long cst = 0;
        for (int k = i + 1; k <= n; k++) {
          cst += sum[k][j];
          for (pair<int, int> z : cd[k][j])
            if (k - z.first >= i) cst -= z.second;
          umin(dp[k][j], dp[i][j] + cst);
        }
        cst = 0;
        for (int k = j + 1; k <= m; k++) {
          cst += sum[i][k];
          for (pair<int, int> z : ab[i][k])
            if (k - z.first >= j) cst -= z.second;
          umin(dp[i][k], dp[i][j] + cst);
        }
      }
  printf("%lld\n", dp[n][m]);
  return 0;
}
