# frozen_string_literal: true

# MaxFlowGraph
class MaxFlow
  def initialize(n = 0)
    @n   = n
    @pos = []
    @g   = Array.new(n) { [] }
  end

  def add_edge(from, to, cap)
    edge_number = @pos.size

    @pos << [from, @g[from].size]

    from_id = @g[from].size
    to_id   = @g[to].size
    to_id += 1 if from == to
    @g[from] << Edge.new(to, to_id, cap)
    @g[to]   << Edge.new(from, from_id, 0)

    edge_number
  end

  def push(edge)
    add_edge(*edge)
  end
  alias << push

  # return edge = [from, to, cap, flow]
  def [](i)
    _e  = @g[@pos[i][0]][@pos[i][1]]
    _re = @g[_e.to][_e.rev]
    [@pos[i][0], _e.to, _e.cap + _re.cap, _re.cap]
  end
  alias get_edge []
  alias edge []

  def edges
    @pos.map do |(to, rev)|
      _e  = @g[to][rev]
      _re = @g[_e.to][_e.rev]
      [to, _e.to, _e.cap + _re.cap, _re.cap]
    end
  end

  def change_edge(i, new_cap, new_flow)
    _e  = @g[@pos[i][0]][@pos[i][1]]
    _re = @g[_e[0]][_e[1]]
    _e.cap  = new_cap - new_flow
    _re.cap = new_flow
  end

  def flow(s, t, flow_limit = 1 << 64)
    level = Array.new(@n)
    iter  = Array.new(@n)
    que   = []

    flow = 0
    while flow < flow_limit
      bfs(level, que, s, t)
      break if level[t] == -1

      iter.fill(0)
      while flow < flow_limit
        f = dfs(t, flow_limit - flow, s, level, iter)
        break if f == 0

        flow += f
      end
    end

    flow
  end
  alias max_flow flow

  def min_cut(s)
    visited = Array.new(@n) { false }
    que = [s]
    while (q = que.shift)
      visited[q] = true
      @g[q].each do |e|
        if e.cap > 0 && !visited[e.to]
          visited[e.to] = true
          que << e.to
        end
      end
    end
    visited
  end

  private

  Edge = Struct.new(:to, :rev, :cap)
  private_constant :Edge

  def bfs(level, que, s, t)
    level.fill(-1)
    level[s] = 0
    que.clear
    que << s

    while (v = que.shift)
      @g[v].each do |e|
        next if e.cap == 0 || level[e.to] >= 0

        level[e.to] = level[v] + 1
        return nil if e.to == t

        que << e.to
      end
    end
  end

  def dfs(v, up, s, level, iter)
    return up if v == s

    res = 0
    level_v = level[v]

    while iter[v] < @g[v].size
      i = iter[v]
      e = @g[v][i]
      re = @g[e.to][e.rev]
      if level_v > level[e.to] && re.cap > 0 then
        d = dfs(e.to, up-res<re.cap ? up-res : re.cap, s, level, iter)
        if d > 0 then
          e.cap += d
          re.cap -= d
          res += d
          break if res == up
        end
      end
      iter[v] += 1
    end

    res
  end
end

MaxFlowGraph = MaxFlow
MFGraph      = MaxFlow

n, m = gets.split.map &:to_i
str = (0 ... n).map{ gets.chomp }

g = MaxFlow.new(n*m+2)
s, t = n*m, n*m+1

n.times{ |i|
  m.times{ |j|
    next if str[i][j] == '#'
    (i+j).even? ? g.add_edge(s, i*m+j, 1) : g.add_edge(i*m+j, t, 1)
    [[i+1, j], [i, j+1]].each{ |x, y|
      if x<n && y<m && str[x][y]=='.' then
        (i+j).even? ? g.add_edge(i*m+j, x*m+y, 1) : g.add_edge(x*m+y, i*m+j, 1)
      end
    }
  }
}

puts g.max_flow(s, t)
es = g.edges

g.edges.each{ |from, to, _, f|
  if from != s && to != t && f == 1 then
    from, to = to, from if from > to
    a, b, c, d = from/m, from%m, to/m, to%m
    if a == c then
      str[a][b] = '>'
      str[c][d] = '<'
    else
      str[a][b] = 'v'
      str[c][d] = '^'
    end
  end
}

str.each{ |s| puts s }


Measured memory_bytes: 25396