#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int h, s;
    cin >> h >> s;
    char table[h][s];
    for(int i=0; i < h; ++i)
    {
        for(int j=0; j < s; ++j)
        {
            cin >> table[i][j];
        }
    }

    enum Figures
    {
        King = 1,
        Bishop = 2,
        Rook = 3,
        Knight = 4,
        Queen = 5
    };

    int x = 1, y = 1;
    Figures current_figure = King;

    int t = 0;
    for(int i=0; i < h-1; ++i)
    {
        for(int j=i; j < s-1; ++j)
        {
            if(table[i][j+1] == '.' && table[i+1][j+1] == '.')
            {
                x++;
                y++;
                t++;
            }
            else if (table[i][j+1] == '.')
            {
                x++;
                t++;
            }
            else if (table[i+1][j] == '.')
            {
                y++;
                t++;
            }
            else
            {
                t=-1;
            }
        }
    }
    cout << t;

    return 0;
}