    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<ll,ll>;
    const int INF=1001001001;
    const int mod=998244353;
    
    int a[505][505],b[505][505];

    void solve(){
      int r,c;
      cin>>r>>c;
      rep(i,r){
        rep(j,c-1){
          cin>>a[i][j];
        }
      }
      rep(i,r-1){
        rep(j,c){
          cin>>b[i][j];
        }
      }
      priority_queue<P,vector<P>,greater<P>>q;
      vector<int>dist(r*c*2,INF);
     
      auto push=[&](int i,int j,int k,int nd){
        int v=i*c*2+j*2+k;
        if(dist[v]<=nd){return;}
        dist[v]=nd;
        q.emplace(nd,v);
      };
      push(0,0,0,0);
      while(!q.empty()){
        auto t=q.top();q.pop();
        int d=t.first,v=t.second;
        if(dist[v]!=d){continue;}
        int i=v/(2*c),j=v/2%c,k=v%2;
        if(k==0){
          if(j+1<c){push(i,j+1,k,d+a[i][j]);}
          if(j-1>=0){push(i,j-1,k,d+a[i][j-1]);}
          if(i+1<r){push(i+1,j,k,d+b[i][j]);}
          push(i,j,1,d+1);
        }
        else{
          if(i-1>=0){push(i-1,j,1,d+1);}
          push(i,j,0,d);
        } 
      }
      cout<<dist[r*c*2-2]<<endl;
    }
    int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      solve();
      return 0;
    }
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  int a,b; cin >> a >> b;
  printf("%.10Lf\n", (ld)(a-b)/a*100);
  return 0;
}
