#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = (4e6 + 10);
char s[2][N];
int n, q;
struct node {
  int a[2][2], tag;
  void ret() {
    for (register int i = (0); i <= (1); ++i)
      for (register int j = (0); j <= (1); ++j)
        if (a[i][j] >= inf) a[i][j] = inf;
  }
  friend node operator+(node A, node B) {
    node C;
    if (A.tag == -1) return B;
    if (B.tag == -1) return A;
    C.a[0][0] = min(A.a[0][0] + B.a[0][0], A.a[0][1] + B.a[1][0]);
    C.a[0][1] = min(A.a[0][0] + B.a[0][1], A.a[0][1] + B.a[1][1]);
    C.a[1][0] = min(A.a[1][0] + B.a[0][0], A.a[1][1] + B.a[1][0]);
    C.a[1][1] = min(A.a[1][0] + B.a[0][1], A.a[1][1] + B.a[1][1]);
    return C;
  }
} t[N << 2];
void print(node A) {
  printf("%d\n%d\n%d\n%d\n", A.a[0][0], A.a[0][1], A.a[1][0], A.a[1][1]);
}
void build(int k, int l, int r) {
  t[k].tag = 1;
  if (l == r) {
    if (s[0][l] == 'X' && s[1][l] == 'X')
      t[k].a[0][0] = t[k].a[0][1] = t[k].a[1][0] = t[k].a[1][1] = inf;
    if (s[0][l] == 'X' && s[1][l] == '.')
      t[k].a[0][0] = t[k].a[0][1] = t[k].a[1][0] = inf, t[k].a[1][1] = 1;
    if (s[0][l] == '.' && s[1][l] == 'X')
      t[k].a[0][0] = 1, t[k].a[1][0] = t[k].a[0][1] = t[k].a[1][1] = inf;
    if (s[0][l] == '.' && s[1][l] == '.')
      t[k].a[0][0] = t[k].a[1][1] = 1, t[k].a[0][1] = t[k].a[1][0] = 2;
    return;
  }
  int mid = l + r >> 1;
  build(k << 1, l, mid);
  build(k << 1 | 1, mid + 1, r);
  t[k] = t[k << 1] + t[k << 1 | 1];
  t[k].ret();
}
node query(int k, int l, int r, int x, int y) {
  if (x <= l && r <= y) return t[k];
  int mid = l + r >> 1;
  node tp;
  tp.tag = -1;
  if (x <= mid) tp = query(k << 1, l, mid, x, y);
  if (mid < y) tp = tp + query(k << 1 | 1, mid + 1, r, x, y);
  tp.ret();
  return tp;
}
signed main() {
  scanf("%d %d", &n, &q);
  scanf("%s", s[0] + 1);
  scanf("%s", s[1] + 1);
  build(1, 1, n);
  int x, y, px, py;
  while (q--) {
    scanf("%d %d", &x, &y);
    (x <= n ? px = 0 : (x -= n, px = 1));
    (y <= n ? py = 0 : (y -= n, py = 1));
    if (x > y) swap(x, y), swap(px, py);
    node ans = query(1, 1, n, x, y);
    printf("%d\n", (ans.a[px][py] - 1 >= 2 * n ? -1 : ans.a[px][py] - 1));
  }
  return 0;
}
