module SimpleUndirectedGraphic
    require 'set'

    def each_connected_component(&block)
        return enum_for(__method__) unless block_given?
        reached = Set.new
        each_node do |s|
            next if reached.include?(s)
            cc = Set[s]
            queue = [s]
            until queue.empty?
                u = queue.shift
                each_neighbour(u) do |v|
                    next if cc.include?(v)
                    cc << v
                    queue << v
                    reached << v
                end
            end
            block.call(cc)
        end
    end
end

class Hash
    include SimpleUndirectedGraphic
    alias each_node each_key
    def each_neighbour(u)
        self[u].each do |v|
            yield(v)
        end
    end
end

loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0
    g = {}
    (1..n).map {|i| g[i] = Set.new}
    m.times do
        u, v = gets.split.map(&:to_i)
        g[u] << v
        g[v] << u
    end

    isolated = 0
    cc = 0

    g.each_connected_component do |a|
        if a.size == 1
            isolated += 1
        else
            cc += 1
        end
    end

    if cc > 0
        p (1 + 2 ** (cc + isolated)) % 1_000_000_007
    else
        p 2 ** isolated % 1_000_000_007
    end
end