module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end

include Memoizable

require 'tsort'
require 'set'

n, m = gets.split.map &:to_i

g = {}
(1..n).each{|i| g[i] = []}

m.times do
	i, j = gets.split.map &:to_i
	g[i] << j
end

class Hash
	include TSort
	alias tsort_each_node each_key
	def tsort_each_child(i)
		self[i].each{|j| yield(j)}
	end
end

component = {}
scc = g.strongly_connected_components.reverse
scc.each_with_index do |a, i|
	a.each do |j|
		component[j] = i
	end
end

$c_g = {}
(0..scc.size-1).each{|i| $c_g[i] = Set.new}

g.each do |from, tos|
	c1 = component[from]
	tos.each do |to|
		c2 = component[to]
		$c_g[c1] << c2 if c1 != c2
	end
end

def f(state, i, n)
	return 1 if i == n
	sum = f(state>>1, i+1, n)
	return sum if state[0] == 1

	stack = [i]
	reached = {i => 1}
	until stack.empty?
		j = stack.pop
		next if !$c_g[j]
		$c_g[j].each do |k|
			next if reached[k]
			reached[k] = 1
			state |= (1 << k-i)
			stack << k
		end
	end

	sum += f(state>>1, i+1, n)
end

memoize :f

p f(0, 0, scc.size) 