<?php

list($r, $c) = explode(' ', getLine());

$r = intval($r);
$c = intval($c);

$map = array();

for ($i = 0; $i < $r; $i ++) {
  $map[$i] = getLine();
}

for ($i = 0; $i < $r; $i ++) {
  if (!isContainS($i, false)) {
    fillMapX($i, false);
  }
}
for ($j = 0; $j < $c; $j ++) {
  if (!isContainS(false, $j)) {
    fillMapX(false, $j);
  }
}

//var_dump($map);

$answer = 0;

for ($i = 0; $i < $r; $i ++) {
  for ($j = 0; $j < $c; $j ++) {
    $answer += $map[$i][$j] == 'X';
  }
}

print $answer;

function getLine() {
  $line = trim(fgets(STDIN));
  return $line;
}

function isContainS($row, $col) {
  global $map;
  global $r;
  global $c;

  if ($row !== false) {
    for ($j = 0; $j < $c; $j ++) {
      if ($map[$row][$j] == 'S') {
        return true;
      }
    }
    return false;
  }
  if ($col !== false) {
    for ($i = 0; $i < $r; $i ++) {
      if ($map[$i][$col] == 'S') {
        return true;
      }
    }
    return false;
  }

  return false;
}

function fillMapX($row, $col) {
  global $map;
  global $r;
  global $c;

  if ($row !== false) {
    for ($j = 0; $j < $c; $j ++) {
      $map[$row][$j] = 'X';
    }
    return true;
  }
  if ($col !== false) {
    for ($i = 0; $i < $r; $i ++) {
      $map[$i][$col] = 'X';
    }
    return true;
  }

  return false;
}


<?php
list($n, $m, $r) = explode(' ', trim(fgets(STDIN)));
if (2*$r > min($n, $m)){
	echo 'Second', PHP_EOL;
}else{
	echo 'First', PHP_EOL;
}


<?php

$__fp = fopen("php://stdin", "r");

$a1 = intval(fgets($__fp));
$a2 = intval(fgets($__fp));
$k1 = intval(fgets($__fp));
$k2 = intval(fgets($__fp));
$n = intval(fgets($__fp));

$amin = $k1 < $k2 ? $a1 : $a2;
$kmin = $k1 < $k2 ? $k1 : $k2;

$amax = $k1 < $k2 ? $a2 : $a1;
$kmax = $k1 < $k2 ? $k2 : $k1;

// min value

$left = $n - (($kmax - 1) * $amax);
if ($left > 0) {
    $left -= (($kmin - 1) * $amin);

    if ($left > 0) {
        $r1 = min($left, $amin + $amax);
    } else {
        $r1 = 0;
    }
} else {
    $r1 = 0;
}

echo $r1;

// max value

$left = $n - ($kmin * $amin);
if ($left > 0) {

    $r2 = $amin + min(floor($left / $kmax), $amax);
} else {
    $r2 = floor($n / $kmin);
}

echo ' ', $r2;


<?php
$line1 = explode(' ', trim(fgets(STDIN)));
$line2 = explode(' ', trim(fgets(STDIN)));
$line3 = explode(' ', trim(fgets(STDIN)));
$res = array_uintersect($line2, $line3, "strcasecmp");
$min = min(min($line2), min($line3));
$max = max(min($line2), min($line3));
if(!empty($res)){
    echo min($res);
}else{
    echo $min.$max;
}


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = array();
$d = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] > 0)
     {
          $c[count($c)] = $b[$x];
     }
     else
     {
          $d[count($d)] = $b[$x];
     }
}
$e = array_sum($c);
$f = array_sum($d);
$g = $e - $f;
print $g;
?>


<?php
$a = explode(' ', trim(fgets(STDIN)));
sort($a);

if ($a[0] == $a[3]) {
    echo $a[4] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[1] == $a[4]) {
    echo $a[0] == $a[5] ? 'Elephant' : 'Bear';
} elseif ($a[2] == $a[5]) {
    echo $a[0] == $a[1] ? 'Elephant' : 'Bear';
} else {
    echo 'Alien';
}


<?php

$aa = readline();
$cnt = 0;
for($i=0; $i<strlen($aa); $i++)
	if($aa[$i] == 'a')
		$cnt++;
echo min(strlen($aa), $cnt*2-1);


<?php

$prime = array();
$sum   = array();
$ans   = array();
$p     = array();
GetPrime();
GetSum();
GetAnswer();

fscanf(STDIN,"%s %s",$num,$k);

//echo $ans[$num]."&".$k;

if( $ans[$num] < $k){
    echo "NO\n";
}else{
    echo "YES\n";
}

function GetAnswer(){
    global $prime;
    global $sum;
    global $ans;
    $bound = 1e4;
    $cnt = 0;
    for($i = 2 ; $i < $bound ; $i++){
        $ans[$i] = ($sum[$cnt] <= $i) ? ( ++$cnt ) : ($cnt);

       // echo $i."->".$ans[$i].", \n";
    }
}

function GetSum(){
    global $prime;
    global $sum;
    global $p;
    $prime_len = count($prime);
    $cnt = 0;
    for($i = 0 ; $i < $prime_len ; $i++){
        if($p[$prime[$i] + $prime[$i+1] + 1]){ // 和也要是素数
            $sum[$cnt++] = $prime[$i] + $prime[$i+1] + 1;
            //echo "sum = ".$sum[$cnt-1]."\n";
        }
    }
}

function GetPrime(){
    global $prime;
    global $p;
    $end = 1e4;
    $p = memset($p,1 , $end);
    $p[1] = 0;
    for ($i = 2 ; $i < $end/2 ; $i ++){
        if($p[$i])
        for ($j = $i+$i ; $j < $end ; $j += $i){
            if($p[$j])
            $p[$j] = 0;
        }
    }
    $cnt = 0;
    for($i = 2 ; $i < $end ; $i++){
        if($p[$i]){
            $prime[$cnt++] = $i;
            //echo $i.",";
        }
    }
    //echo "count:".count ($prime);
}

function memset($arr , $value , $length){
    for ($i = 0 ; $i < $length ; $i++){
        array_push($arr,$value);
    }
    return $arr;
}
?>


<?php
fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%s",$str);
$alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$split=str_split($alpha);
for ($i=0; $i <strlen($str)-3 ; $i++)
{
	$str1=substr($str,$i,4);
    $frst=implode(array_keys($split,$str1[0]));
    $secnd=implode(array_keys($split,$str1[1]));
    $thrd=implode(array_keys($split,$str1[2]));
    $frth=implode(array_keys($split,$str1[3]));

		if($frst>13)

			$g1=abs($frst-26);
			//echo "$g1\n";

		else
			$g1=$frst;

		if($secnd>15)
			$g2=abs($secnd-28);
		else

			$g2=abs($secnd-2);
			//echo "$g2\n";

		if($thrd<6)
			$g3=abs($thrd+7);
		else
			$g3=abs(19-$thrd);

		if($frth>19)
			$g4=abs(32-$frth);
		else
			$g4=abs($frth-6);
		$count[$i]=$g1+$g2+$g3+$g4;

}
$min=$count[0];
for ($i=0; $i <count($count); $i++)
{
	if($count[$i]<$min)
	{
		$min=$count[$i];
	}
}
echo "$min";


<?php
      $t = array();
      list($n) = explode(' ', trim(fgets(STDIN)));
      list($x1, $y1) = explode(' ', trim(fgets(STDIN)));
      list($x2, $y2) = explode(' ', trim(fgets(STDIN)));
      list($x3, $y3) = explode(' ', trim(fgets(STDIN)));
      $ans1 = $n - $x2 - $x3;
      if($ans1 > $y1)
        $ans1 = $y1;
      $n -= $ans1;
      $ans2 = $n - $x3;
      if($ans2 > $y2)
        $ans2 = $y2;
      $ans3 = $n - $ans2;
      echo $ans1;
      echo " ";
      echo $ans2;
      echo " ";
      echo $ans3;
?>