There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior.

There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself.

Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake.

Input

The first line contains two positive integers n and s (1 ≤ n ≤ 2·105, 1 ≤ s ≤ n) — the number of workers and the id of the chief.

The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n - 1), where ai is the number of superiors (not only immediate) the worker with id i reported about.

Output

Print the minimum number of workers that could make a mistake.

Examples

input

3 2

2 0 2

output

1

input

5 3

1 0 0 4 1

output

2

Note

In the first example it is possible that only the first worker made a mistake. Then:

the immediate superior of the first worker is the second worker,

the immediate superior of the third worker is the first worker,

the second worker is the chief.

**题意:**给定n个点,每个点只有一个直接的父亲节点,然后给出每个点的上级数量(包括父亲的父亲),且规定第s个点是根节点,问其中最少改几个就能构造出合法树。
**思路:**开始想使用数据结构,然后判断深度,不对就改,但是这样贪心是不对的。我们可以想到如果符合要求,那么排好序后的上级数量,两两之间一定是相同的或者是连续的。而当某个点的值不连续了,那么说明其后的所有点都不对了,合理的贪心是该把排最后的数变成缺少的数字,然后继续判断。注意如果有多个0,如果它不是根,那么说明这个数一定是需要变换的。另外注意判断第s个点不为0的情况。

/** @Date    : 2016-11-20-18.15

* @Author : Lweleth (SoungEarlf@gmail.com)

* @Link : https://github.com/

* @Version :

*/

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <algorithm>

#include <utility>

#include <vector>

#include <map>

#include <set>

#include <string>

#include <stack>

#include <queue>

//#include<bits/stdc++.h>

#define LL long long

#define MMF(x) memset((x),0,sizeof(x))

#define MMI(x) memset((x), INF, sizeof(x))

using namespace std;



const int INF = 0x3f3f3f3f;

const int N = 1e5+20;





int a[N*2];


int main()

{

int n, s, cnt;

cin >> n >> s;

for(int i = 0; i < n; i++)

{

scanf("%d", a + i);

if(i != s-1 && a[i] == 0)

a[i] = INF;

}

cnt = 0;

if(a[s-1] != 0)

cnt++;

a[s-1] = 0;

int nw = 1;

sort(a, a + n);

for(int i = 1; i < n; nw++)

{



if(nw != a[i])

{

cnt++;

n--;

}

else

{

while(a[i] == nw)

i++;

}

}

cout << cnt << endl;

return 0;

}


最新文章

  1. 函数对象(仿函数 functor)
  2. 菜鸟学自动化测试(一)---- selenium IDE
  3. 【windows 下安装 mysql-server 无法登录问题解决】
  4. Inno setup定制安装界面
  5. jsp_属性范围_session
  6. android viewpager change adapter ---在使用viewpager设置新的adapter的时候发现页面还是显示旧的adapter中的值
  7. js制作圆角按钮(兼容谷歌,ie7,ie8)
  8. Semaphore实现Andoird版源代码剖析
  9. java操作mongodb——连接数据库
  10. C++ 头文件系列(streambuf)
  11. JavaScript事件(二)
  12. 解决PhpStorm卡顿的问题
  13. 跨平台数据库工具Azure Data Studio
  14. BZOJ2588 主席树 + 树上差分
  15. 《剑指offer》把数组排成最小的数
  16. 无序hashset与hashmap让其有序
  17. video.js使用
  18. jQuery-数据管理-删除事件
  19. 用链表实现nodejs的内存对象管理
  20. vulkan

热门文章

  1. vue.js学习之 如何在better-scroll加载完成后,自动滚动到最底部
  2. Java接口与继承作业
  3. ubuntu apache nginx 启动 关闭
  4. Java容器之Collections
  5. 理解windows模型
  6. C# WebBrowser控件详解
  7. 扩展SplitContainer控件
  8. 委托,事件,lambda表达式
  9. dpr dproj 扩展名区别,dprdproj
  10. 【Python】PYTHON 函数局部变量和全局变量