#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c=0;
double d;
cin>>a>>b;
int x[a][b],y[a][b];
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
cin>>x[i][j];
}
}
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
cin>>y[i][j];
}
}
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
if(x[i][j]==y[i][j]){
c++;
}
}
}
d=a*b/c/100.0;
printf("%.2f",d);
return 0;
}