<?xml version="1.0"?>
<informationTable xsi:schemaLocation="http://www.sec.gov/edgar/document/thirteenf/informationtable eis_13FDocument.xsd"
	xmlns="http://www.sec.gov/edgar/document/thirteenf/informationtable"
	xmlns:n1="http://www.sec.gov/edgar/document/thirteenf/informationtable"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<infoTable>
		<nameOfIssuer>AMETEK INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>031100100</cusip>
		<value>162428876</value>
		<shrsOrPrnAmt>
			<sshPrnamt>863983</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>774173</Sole>
			<Shared>89500</Shared>
			<None>310</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>AMPHENOL CORP NEW</nameOfIssuer>
		<titleOfClass>CL A</titleOfClass>
		<cusip>032095101</cusip>
		<value>191739124</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1549407</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>1393321</Sole>
			<Shared>155459</Shared>
			<None>627</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>ARCH CAP GROUP LTD</nameOfIssuer>
		<titleOfClass>ORD</titleOfClass>
		<cusip>G0450A105</cusip>
		<value>99459405</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1096213</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>977376</Sole>
			<Shared>118500</Shared>
			<None>337</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>BERKLEY W R CORP</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>084423102</cusip>
		<value>81510267</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1063825</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>956950</Sole>
			<Shared>106500</Shared>
			<None>375</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>BERKSHIRE HATHAWAY INC DEL</nameOfIssuer>
		<titleOfClass>CL B NEW</titleOfClass>
		<cusip>084670702</cusip>
		<value>339350</value>
		<shrsOrPrnAmt>
			<sshPrnamt>675</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>675</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>CANADIAN PACIFIC KANSAS CITY</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>13646K108</cusip>
		<value>100367698</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1347398</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>1199848</Sole>
			<Shared>147000</Shared>
			<None>550</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>COPART INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>217204106</cusip>
		<value>87841700</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1953340</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>1761407</Sole>
			<Shared>190992</Shared>
			<None>941</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>GRACO INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>384109104</cusip>
		<value>65374441</value>
		<shrsOrPrnAmt>
			<sshPrnamt>769473</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>685145</Sole>
			<Shared>84060</Shared>
			<None>268</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>HEICO CORP NEW</nameOfIssuer>
		<titleOfClass>CL A</titleOfClass>
		<cusip>422806208</cusip>
		<value>152070374</value>
		<shrsOrPrnAmt>
			<sshPrnamt>598490</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>598206</Sole>
			<Shared>0</Shared>
			<None>284</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>HINGHAM INSTN SVGS MASS</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>433323102</cusip>
		<value>54057108</value>
		<shrsOrPrnAmt>
			<sshPrnamt>204933</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>184828</Sole>
			<Shared>20000</Shared>
			<None>105</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>IDEX CORP</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>45167R104</cusip>
		<value>40512267</value>
		<shrsOrPrnAmt>
			<sshPrnamt>248908</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>220273</Sole>
			<Shared>28527</Shared>
			<None>108</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>KINSALE CAP GROUP INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>49714P108</cusip>
		<value>84975306</value>
		<shrsOrPrnAmt>
			<sshPrnamt>199820</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>180752</Sole>
			<Shared>19000</Shared>
			<None>68</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>LINDE PLC</nameOfIssuer>
		<titleOfClass>SHS</titleOfClass>
		<cusip>G54950103</cusip>
		<value>127887744</value>
		<shrsOrPrnAmt>
			<sshPrnamt>269237</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>241187</Sole>
			<Shared>27950</Shared>
			<None>100</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>MASTERCARD INCORPORATED</nameOfIssuer>
		<titleOfClass>CL A</titleOfClass>
		<cusip>57636Q104</cusip>
		<value>1185969</value>
		<shrsOrPrnAmt>
			<sshPrnamt>2085</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>2085</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>PROGRESSIVE CORP</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>743315103</cusip>
		<value>3321478</value>
		<shrsOrPrnAmt>
			<sshPrnamt>13450</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>13450</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>RBC BEARINGS INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>75524B104</cusip>
		<value>173265733</value>
		<shrsOrPrnAmt>
			<sshPrnamt>443941</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>399757</Sole>
			<Shared>44000</Shared>
			<None>184</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>RLI CORP</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>749607107</cusip>
		<value>110177033</value>
		<shrsOrPrnAmt>
			<sshPrnamt>1689314</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>1526664</Sole>
			<Shared>162000</Shared>
			<None>650</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>SIMPSON MFG INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>829073105</cusip>
		<value>70850498</value>
		<shrsOrPrnAmt>
			<sshPrnamt>423089</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>372944</Sole>
			<Shared>50000</Shared>
			<None>145</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>SPDR S&amp;P MIDCAP 400 ETF TR</nameOfIssuer>
		<titleOfClass>UTSER1 S&amp;PDCRP</titleOfClass>
		<cusip>78467Y107</cusip>
		<value>574573</value>
		<shrsOrPrnAmt>
			<sshPrnamt>964</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>964</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>TELEDYNE TECHNOLOGIES INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>879360105</cusip>
		<value>185741276</value>
		<shrsOrPrnAmt>
			<sshPrnamt>316943</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>285542</Sole>
			<Shared>31275</Shared>
			<None>126</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>THERMO FISHER SCIENTIFIC INC</nameOfIssuer>
		<titleOfClass>COM</titleOfClass>
		<cusip>883556102</cusip>
		<value>1376972</value>
		<shrsOrPrnAmt>
			<sshPrnamt>2839</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>2839</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
	<infoTable>
		<nameOfIssuer>VISA INC</nameOfIssuer>
		<titleOfClass>COM CL A</titleOfClass>
		<cusip>92826C839</cusip>
		<value>1144306</value>
		<shrsOrPrnAmt>
			<sshPrnamt>3352</sshPrnamt>
			<sshPrnamtType>SH</sshPrnamtType>
		</shrsOrPrnAmt>
		<investmentDiscretion>SOLE</investmentDiscretion>
		<votingAuthority>
			<Sole>3352</Sole>
			<Shared>0</Shared>
			<None>0</None>
		</votingAuthority>
	</infoTable>
</informationTable>
