#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>

using namespace std;

int i;

int nadjiX(vector<long long> A, vector<long long>B){
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    vector<long long> razlika; 
    vector <long long> ::iterator it;
    vector <long long> ::iterator bit=B.end();
    for(i = 0; i < A.size() - 1; i++){
        razlika.push_back(A[i+1]-A[i]);
    }
    long long x = *min_element(razlika.begin(),razlika.end());
    it = A.begin();
    while((*it)-x > 0){
        *it -= x;
    }
    long long prvi = *it;
    A.clear();
    int size=(*bit/x);

    if (*bit % x == 0 ) {
    }
    else size++;

    A.resize(size);
    it = A.begin();
    A.clear();
    for (i=0;i<size;i++) {
        A.push_back(prvi+x*i);
    }

    for (it = A.begin() ; it != A.end(); ++it) {
        for (bit = B.begin() ; bit != B.end(); ++bit)
        if(*it==*bit) {
            return 0;
        }
    }
    return 1;
}

int main(){
    vector<long long>A,B;
    A.push_back(6);
     A.push_back(4);
      A.push_back(2);

    B.push_back(21);
     B.push_back(49);
     printf("%d",nadjiX(A,B));
     return 0;
}