N,M = gets.split.map &:to_i
gs = {}
M.times {
  u,v = gets.split.map &:to_i
  (0...3).each{ |i|
    uu = u*10+i; vv = v*10+(i+1)%3
    gs[uu] ||= {}
    gs[uu][vv] = 1
  }
}
S,T = gets.split.map{ |s| s.to_i * 10 }
#p gs

ans = 1
visited = {}
queue = (gs[S] || {}).keys
while queue.size > 0 do
  vs = {}
  queue.each{ |u| visited[u] = 1 }
  queue.each{ |u|
    if u == T
      p ans / 3; exit
    end
    (gs[u] || {}).keys.each{ |v|
      next if visited[v]
      vs[v] = 1
    }
  }
  queue = vs.keys
  ans += 1
end
p -1