#!/usr/bin/env ruby
# coding: utf-8

class Integer
  def bit_length
    Math.log2(self+1).ceil
  end
end

class PQ
  def initialize(base=0)
    @base = base
    @table = []
  end

  def add(prio, val)
    prio -= @base
    bitlen = prio.bit_length
    case bitlen
    when 0, 1
      unless @table[bitlen]
        @table[bitlen] = []
      end
      @table[bitlen] << val
    else
      unless @table[bitlen]
        @table[bitlen] = PQ.new(2 ** (bitlen-1))
      end
      @table[bitlen].add(prio, val)
    end
  end

  def to_s
    str = "PQ("
    sep = ""
    @table.each_with_index do |t, i|
      if t
        str += "#{sep} #{i}(#{(@base+i).to_s(16)}): #{t}"
        sep = ","
      end
    end
    str + ")"
  end

  def shift
    @table.each do |child|
      next unless child
      x = child.shift
      return x if x
    end
    nil
  end
end

class Stage

  def initialize
    @table = []
  end
  def to_s
    "Stage: #{@table}"
  end

  class Node
    def initialize
      @a = []
      @b = []
    end
    attr_accessor :a, :b, :d
    def to_s
      @d == nil ? "node" : "node distance:#{@d}"
    end
  end

  def [](n)
    unless @table[n]
      @table[n] = Node.new
    end
    @table[n]
  end

  class Vector
    def initialize(a, b, c)
      @a = a
      @b = b
      @c = c
    end
    attr_reader :a, :b, :c
    attr_accessor :d
    def to_s
      "#{a}=>#{b} coin=#{c}, distance=#{d}"
    end
  end

  def add(a, b, c)
    v = Vector.new(a, b, c)
    self[a].a << v
    self[b].b << v
    v
  end

  def distance(start, goal, p)
    ss = Stage.new
    pq = PQ.new(-2**16)
    self[start].a.each do |v1|
      v2 = ss.add(v1.a, v1.b, v1.c)
      v2.d = p - v2.c
      #puts "<= #{v2}"
      pq.add(v2.d, v2)
    end
    while v2 = pq.shift
      #puts "=> #{v2}"
      next if ss[v2.b].d
      return v2.d if v2.b == goal
      ss[v2.b].d = v2.d
      self[v2.b].a.each do |v1|
        v3 = ss.add(v1.a, v1.b, v1.c)
        v3.d = p - v3.c
        pq.add(v3.d, v3)
      end
    end
    return 1
  end
end

n, m, p = ARGF.gets.split.map(&:to_i)
s1 = Stage.new
m.times do
  s1.add(*ARGF.gets.split.map(&:to_i))
end

d1 = s1.distance(1, n, p)
d2 = s1.distance(n, n, p)

if d2 >= 0
  puts d1 >= 0 ? 0 : -d1
else
  puts "-1"
end
