Greedy line breaks for 2 lines

I have some text to typeset which is short enough so that it fits to either 1 or 2 lines. I'm using \raggedright.

I'd like to set up parameters like \hyphenpenalty so that as much as possible would be put to the first line without creating underfull or overfull hboxes. If it is possible to hyphanate a word (and that would produce more text in the first line), then it should be hyphenated at the last possible position.

I was trying to change many settings including \pretolerance-1, but I couldn't make it work.

For example, here:

\documentclass{article}
\usepackage{t1enc}
\begin{document}
\hrule width137pt height 1pt
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\break\'al\-lo\-m\'as \par}
\bigskip
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo-\break m\'as \par}
\vbox{\hsize137pt\parindent0pt\sf\raggedright
\pretolerance-1
\hyphenpenalty1
\exhyphenpenalty2
\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}
\end{document}


, it's possible to fit Kunszentmárton, autóbusz-állo- to the 1st line, but if LaTeX is breaking the line automatically, then it only puts only Kunszentmárton, there (see in the last \vbox). How do I put as much as possible to the first line?

I know that TeX's line breaking algorithm optimizes paragraphs globally, and it's close to impossible to configure it to make it greedy, but maybe there is an easy solution when the text first to 1 or 2 lines.

I know about Can I locally switch to a 'greedy' justification algorithm? and \linebylinepar in its answer http://tex.stackexchange.com/a/131275/820, but even that one wouldn't put Kunszentmárton, autóbusz-állo- to the 1st line.

-
fwiw, all your accented letters prevent hyphenation of the word they're in; \usepackage{t1enc} doesn't avoid the hyphenation effects of accent primitives; use \usepackage{fontenc} instead. i suspect this hasn't any effect here, since you're not using hyphenation. –  wasteofspace May 28 at 16:53
I don't need automatic hyphenation in this example, I've inserted all hyphens I need manually. –  pts May 28 at 21:45

Solving this is the main aim of the ragged2e package, see the added last example:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\begin{document}
\hrule width137pt height 1pt
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\break\'al\-lo\-m\'as \par}
\bigskip
\vbox{\hsize137pt\parindent0pt\sf\raggedright\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo-\break m\'as \par}

\vbox{\hsize137pt\parindent0pt\sf\raggedright
\pretolerance-1
\hyphenpenalty1
\exhyphenpenalty2
\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}

\bigskip
\hrule
\bigskip

\vbox{\hsize137pt\sf\RaggedRight
\par
Kun\-szent\-m\'ar\-ton, au\-t\'obusz-\'al\-lo\-m\'as \par}

\end{document}

-