#include <bits/stdc++.h>
using namespace std;
int dist[2][200005], par[2][200005];
int main() {
  int n, q;
  cin >> n >> q;
  char a[2][n + 2];
  for (int i = 0; i < 2; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  a[0][0] = 'X';
  a[1][0] = 'X';
  a[0][n + 1] = 'X';
  a[1][n + 1] = 'X';
  vector<int> poses;
  for (int j = 1; j <= n; j++) {
    if (a[0][j] == '.' && a[1][j] == 'X') {
      if (a[0][j - 1] == 'X') {
        dist[0][j] = 1;
        par[0][j] = j;
      } else {
        dist[0][j] = dist[0][j - 1] + 1;
        par[0][j] = par[0][j - 1];
      }
      poses.push_back(j);
    }
    if (a[0][j] == 'X' && a[1][j] == '.') {
      if (a[1][j - 1] == 'X') {
        dist[1][j] = 1;
        par[1][j] = n + j;
      } else {
        dist[1][j] = dist[1][j - 1] + 1;
        par[1][j] = par[1][j - 1];
      }
      poses.push_back(j);
    }
    if (a[0][j] == '.' && a[1][j] == '.') {
      if (a[0][j - 1] == '.' && a[1][j - 1] == '.') {
        dist[0][j] = min(dist[0][j - 1], dist[1][j - 1] + 1) + 1;
        par[0][j] = par[0][j - 1];
        dist[1][j] = min(dist[1][j - 1], dist[0][j - 1] + 1) + 1;
        par[1][j] = par[1][j - 1];
      } else if (a[0][j - 1] == '.' && a[1][j - 1] == 'X') {
        dist[0][j] = dist[0][j - 1] + 1;
        dist[1][j] = dist[0][j] + 1;
        par[0][j] = par[0][j - 1];
        par[1][j] = par[0][j];
      } else if (a[0][j - 1] == 'X' && a[1][j - 1] == '.') {
        dist[1][j] = dist[1][j - 1] + 1;
        dist[0][j] = dist[1][j] + 1;
        par[1][j] = par[1][j - 1];
        par[0][j] = par[1][j];
      } else if (a[0][j - 1] == 'X' && a[1][j - 1] == 'X') {
        dist[0][j] = 1;
        dist[1][j] = 2;
        par[0][j] = j;
        par[1][j] = j;
      }
    }
  }
  while (q--) {
    int x, y;
    cin >> x >> y;
    int x1, x2, y1, y2;
    x1 = x / n, x2 = x % n;
    y1 = y / n, y2 = y % n;
    if (x2 == 0) {
      x2 = n;
      x1--;
    }
    if (y2 == 0) {
      y2 = n;
      y1--;
    }
    if (par[x1][x2] != par[y1][y2]) {
      cout << -1 << endl;
    } else {
      if (y2 < x2) {
        swap(x2, y2);
        swap(x1, y1);
      }
      auto f1 = lower_bound(poses.begin(), poses.end(), x2);
      auto s1 = upper_bound(poses.begin(), poses.end(), y2);
      if (s1 == poses.begin() || f1 == poses.end()) {
        cout << y2 - x2 + (x1 != y1) << endl;
      } else {
        int f = *f1, s = *(--s1);
        if (s < f) {
          cout << y2 - x2 + (x1 != y1) << endl;
          continue;
        }
        int summ = 0;
        summ += f - x2 + y2 - s;
        summ += dist[0][s] + dist[1][s] - dist[0][f] - dist[1][f];
        if (x1 == 0 && a[0][f] == 'X') summ++;
        if (x1 == 1 && a[1][f] == 'X') summ++;
        if (y1 == 0 && a[0][s] == 'X') summ++;
        if (y1 == 1 && a[1][s] == 'X') summ++;
        cout << summ << endl;
      }
    }
  }
  return 0;
}
