#include<bits/stdc++.h>
#define re register
#define N 1000005
#define mod 1000000007
using namespace std;
template<typename _int>
inline void read(re _int&x){
	re _int res=0,flag=1;re char opt;
	while((opt=getchar())<'0'||opt>'9')if(opt=='-')flag=-1;
	while(opt>='0'&&opt<='9'){res=(res<<1)+(res<<3)+opt-48;opt=getchar();}
	x=res*flag;
}
typedef long long ll; 
int n;
ll dp[N],sum[N];
int main(void){
	re int i;*dp=1;*sum=1;
	read(n);
	for(i=1;i<=n;++i){
		(dp[i]+=(sum[i-1]-dp[i-2]*(i-2))%mod+n-1)%mod;
//		printf("%lld %lld\n",sum[i-1],((i>=2)?dp[i-2]:0));
		sum[i]=(sum[i-1]+dp[i]*i)%mod;
	}
	printf("%lld\n",(sum[n-2]*(n-1)%mod*(n-1)%mod+dp[n-1]*(n-1)%mod+dp[n])%mod);
	return 0;
}
