#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int oo = (N << 1);
int dp[19][N][2][2];
int d1[N], d2[2][N];
char mat[2][N];
int cal(int x1, int y1, int x2, int y2) {
  if (x1 == x2) {
    return d2[x2][y1];
  }
  return min(d1[y1] + d2[x2][y1], d2[x1][y1] + d1[y2]);
}
int p[N << 1];
int fi(int x) { return x == p[x] ? x : p[x] = fi(p[x]); }
void update(int x, int y) {
  int f1 = fi(x);
  int f2 = fi(y);
  if (f1 != f2) {
    p[f1] = f2;
  }
}
void init(int n) {
  for (int i = 0; i < (n << 1); i++) {
    p[i] = i;
  }
  for (int i = 0; i < n; i++) {
    if (mat[0][i] == 'X' || mat[1][i] == 'X') {
      d1[i] = oo;
    } else {
      update(i, i + n);
      d1[i] = 1;
    }
    for (int j = 0; j < 2; j++) {
      if (mat[j][i] == 'X' || mat[j][i + 1] == 'X') {
        d2[j][i] = oo;
      } else {
        if (i + 1 < n) {
          update(j * n + i, j * n + i + 1);
        }
        d2[j][i] = 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        if (j == k) {
          dp[0][i][j][k] = 0;
        } else {
          dp[0][i][j][k] = d1[i];
        }
      }
    }
  }
  for (int d = 0; d < 18; d++) {
    for (int i = 0; i < n; i++) {
      for (int x1 = 0; x1 < 2; x1++) {
        for (int y1 = 0; y1 < 2; y1++) {
          dp[d + 1][i][x1][y1] = oo;
          for (int x2 = 0; x2 < 2; x2++) {
            for (int y2 = 0; y2 < 2; y2++) {
              dp[d + 1][i][x1][y1] =
                  min(dp[d + 1][i][x1][y1],
                      dp[d][i][x1][x2] + dp[d][i + (1 << d)][y2][y1] +
                          cal(x2, i + (1 << d) - 1, y2, i + (1 << d)));
            }
          }
        }
      }
    }
  }
}
int query(int x1, int y1, int x2, int y2) {
  int d = (y2 - y1);
  int r[2] = {dp[0][y1][x1][0], dp[0][y1][x1][1]};
  int x = y1;
  for (int i = 18; i && (d + 1); i--) {
    while ((1 << i) & (d + 1)) {
      int tmp[2];
      tmp[0] = min(r[0] + dp[i][x][0][0], r[1] + dp[i][x][1][0]);
      tmp[1] = min(r[0] + dp[i][x][0][1], r[1] + dp[i][x][1][1]);
      r[0] = tmp[0];
      r[1] = tmp[1];
      d -= (1 << i);
      d++;
      x += (1 << i);
      x--;
    }
  }
  return r[x2];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  scanf("%s%s", mat[0], mat[1]);
  init(n);
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    pair<int, int> q1 = make_pair(x % n, x / n), q2 = make_pair(y % n, y / n);
    if (q1 > q2) {
      swap(q1, q2);
    }
    int ans = -1;
    if (fi(x) == fi(y)) {
      ans = query(q1.second, q1.first, q2.second, q2.first);
    }
    printf("%d\n", ans);
  }
  return 0;
}
