#include <bits/stdc++.h>
using namespace std;
int col, a[200008][3], f[200008][3], c[200008][3], nxt[200008][3];
int main() {
  char ch;
  int i, j, n, q, s, l, r, l2, r2, ans;
  scanf("%d %d\n", &n, &q);
  s = 0;
  for (i = 1; i <= n; ++i) {
    scanf("%c", &ch);
    if (ch == 'X') {
      a[i][0] = 1;
      s = i;
    }
  }
  s = 0;
  scanf("\n");
  for (i = 1; i <= n; ++i) {
    scanf("%c", &ch);
    if (ch == 'X') {
      a[i][1] = 1;
      s = i;
    }
  }
  s = n + 1;
  for (i = n; i; --i) {
    if (a[i][0]) s = i;
    nxt[i][0] = s;
  }
  s = n + 1;
  for (i = n; i; --i) {
    if (a[i][1]) s = i;
    nxt[i][1] = s;
  }
  a[n + 1][0] = a[n + 1][1] = 1;
  i = 1;
  s = j = 0;
  while (i <= n) {
    while (i <= n && a[i][0] && a[i][1]) ++i;
    if (i > n) break;
    j = a[i][0];
    s = 0;
    ++col;
    while (i <= n) {
      while (i <= n && !a[i][j]) {
        f[i][j] = ++s;
        c[i][j] = col;
        ++i;
      }
      if (!a[i - 1][j ^ 1] && !a[i][j ^ 1]) {
        --i;
        j ^= 1;
      } else
        break;
    }
  }
  for (i = 1; i <= q; ++i) {
    scanf("%d %d", &l, &r);
    if (l == r) {
      printf("0\n");
      continue;
    }
    if (l <= n)
      l2 = 0;
    else {
      l -= n;
      l2 = 1;
    }
    if (r <= n)
      r2 = 0;
    else {
      r -= n;
      r2 = 1;
    }
    if (l == r) {
      printf("1\n");
      continue;
    }
    if (l > r) {
      swap(l, r);
      swap(l2, r2);
    }
    if (nxt[l][l2] > r) {
      printf("%d\n", r - l + (l2 ^ r2));
      continue;
    }
    ans = nxt[l][l2] - l;
    l = nxt[l][l2] - 1;
    l2 ^= 1;
    if (!f[l][l2]) {
      ++ans;
      l2 ^= 1;
    }
    if (!f[r][r2]) {
      ++ans;
      r2 ^= 1;
    }
    if (a[l][l2] || a[r][r2] || c[l][l2] != c[r][r2]) {
      printf("-1\n");
      continue;
    }
    printf("%d\n", ans + f[r][r2] - f[l][l2]);
  }
  return 0;
}
