function [tc,Rc] = FindFirstCollision(M,R)
syms t;
tc = [];
for i = 2:length(M{1,1})
   for j = 1:size(M,1)
       for k = 1:size(M,1)
           t0 = M{j,1}(i-1);
           t1 = M{j,1}(i);
           s1 = M{j,2}(i-1,:);
           g1 = M{j,2}(i,:);
           s2 = M{k,2}(i-1,:);
           g2 = M{k,2}(i,:);
           l1 = s1+(t-t0)/(t1-t0)*(g1-s1);
           l2 = s2+(t-t0)/(t1-t0)*(g2-s2);
           dist = sqrt((l1(1)-l2(1))^2+(l1(2)-l2(2))^2)-2*R;
           %sgn0 = subs(dist,t,t0);
           tsol = solve(dist,t);
           if(tsol < tc || isempty(tc))
               tc = tsol;
               Rc = [j;k]
           end
       end
   end
end
end