#include<bits/stdc++.h>
using namespace std ;

#define inf 1000000000

int dp[1000][1000] = {0} ; //dp[i][j] = j??\????????????i??????????????????????¨??????´??????????°????
int maps[1000][1000] = {0} ;
int d[1000] = {0} ;
int c[1000] = {0} ;

void id (int i ,int j )
{
    int res1 = 0 ;
    int res2 = 0 ;

    /*
    if (i ==0 && j == 0)
    {
        dp[i][j] = 0 ;
        res2 = dp[i + 1][j + 1] = d[i] * c[j] ;
        //cout << "[debug:dp[" << i+1 << "][" << j+1 << "] = " << dp[i+1][j+1] << "]" << endl ;
    }
    else if (i == 0)
    {
        dp[i][j] = 0 ;
        //cout << "[debug;i = " << i << ":j = " << j << ":skip]" << endl ;
    }
    else if (dp[i][j] == 0 && dp[i - 1][j] == 0)
    {
        dp[i][j] = 0 ;
    }
    else
    {

        res1 = dp[i][j] ;
        res2 = d[i - 1] * c[j + 1] ;

        if (dp[i][j + 1] != 0 && res1 != 0)
        {
            dp[i][j + 1] = min(dp[i][j + 1] ,res1 ) + dp[i][j] ;
        }
        else if (dp[i][j + 1] == 0)
        {
            dp[i][j + 1] = res1 +dp[i][j] ;
        }

        if (dp[i + 1][j + 1] != 0 && res2 != 0)
        {
            dp[i + 1][j + 1] = min(dp[i + 1][j + 1] ,res2 ) + dp[i][j] ;
        }
        else if (dp[i + 1][j + 1] == 0)
        {
            dp[i + 1][j + 1] = res2 + dp[i][j] ;
        }
    }
    */
    if (i == 0)
    {
        dp[i][j] = 0 ;
    }
    else if (i > j)
    {
        dp[i][j] = inf ;
    }
    else
    {
        res1 = dp[i - 1][j - 1] + maps[i][j-1];
        res2 = dp[i][j - 1] ;

        int cmp = 0 ;
        cmp = min(res1 ,res2 ) ;
        dp[i][j] = cmp ;

        //cout << "[debug:maps[" << i << "][" << j-1 << "] = " << maps[i][j-1] << "]" << endl ;
    }

    //cout << "[debug:res1 = " << res1 << ":res2 = " << res2 << "]" << endl ;
    //cout << "[debug:dp[" << i+1 << "][" << j << "] = " << dp[i+1][j] << ":dp[" << i+1 << "][" << j+1 << "] = " << dp[i+1][j+1] << "]" << endl ;
}

int main ()
{
    int n = 0 ,m = 0 ;
    cin >> n >> m ;

    for (int i = 0 ;i < n ;i++ )
    {
        cin >> d[i] ;
    }
    for (int j = 0 ;j < m ;j++ )
    {
        cin >> c[j] ;
    }

    for (int j = 0 ;j <= m ;j++ )
    {
        for (int i = 0 ;i <= n ;i++ )
        {
            maps[i][j] = d[i - 1] * c[j] ;
        }
    }

    /*
    for (int j = 0 ;j < m ;j++ )
    {
        cout << "[debug:maps[" << j << "][] = {" ;
        for (int i = 0 ;i <= n ;i++ )
        {
            cout << " " << maps[i][j] ;
        }
        cout << " }]" << endl ;
    }
    */

    for (int j = 0 ;j <= m ;j++ )
    {
        for (int i = 0 ;i <= n ;i++ )
        {
            //if (i == j + 1) break ;
            id (i ,j ) ;
            //cout << "[debug:dp[" << i << "][" << j << "] = " << dp[i][j] << "]" << endl ;
            //cout << endl ;
        }
    }

    /*
    for (int i = 0 ;i <= n ;i++ )
    {
        cout << "[debug:dp[" << i << "][] = {" ;
        for (int j = 0 ;j < m ;j++ )
        {
            cout << " " << dp[i][j] ;
        }
        cout << " }]" << endl ;
    }
    cout << endl ;

    for (int j = 0 ;j <= m ;j++ )
    {
        cout << "[debug:dp[][" << j << "] = {" ;
        for (int i = 0 ;i <= n ;i++ )
        {
            cout << " " << dp[i][j] ;
        }
        cout << " }]" << endl ;
    }
    */

    cout << dp[n][m] << endl ;

    return 0 ;
}

Measured memory_bytes: 9488