#include <iostream>
#include<vector>
using namespace std;

int main() {
	// your code goes here
	int a;
	cin>>a;
	vector<int> v(a);
	int *ar=new int[a];
	v.clear();
	for(int i=1;i<=a;i++ )
	v[i-1]=i;
	for(int i=0;i<a;i++ )
	cin>>ar[i];

	int c=0;
	for(int i=0;i<a;i++)
	{
		for(int j=0;j<a;j++)
		{
			if(v[i]==ar[j])
		{	c++;
		break; }
		}
	}

	cout<<a-c;

	return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {
	// your code goes here
	int a;
	cin>>a;
	vector<int> v(a);
	int *ar=new int[a];
	v.clear();
	for(int i=1;i<=a;i++ )
	v[i-1]=i;
	for(int i=0;i<a;i++ )
	cin>>ar[i];

	for(int i=0;i<a;i++)
	{
		for(int j=0;j<a;j++)
		{
			if(v[i]==ar[j])
		{	v[i]==1000000;
		ar[i]==1000000; }
		}
	}
	int c=0;
	for(int i=0;i<a;i++)
	if(v[i]!=1000000)
	c++;

	cout<<c/2;

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,i,j,t,sum;
	int s[5555];
	int a[5555];
	while(scanf("%d",&n)!=EOF)
	{
		memset(a,0,sizeof(a));
		t=0;sum=0;
		for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);

	       a[s[i]]++;
	}

	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
		t++;
	}
		printf("%d\n",t);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,i,j,t,sum;
	int s[5555];
	while(scanf("%d",&n)!=EOF)
	{
		t=0;sum=0;
		for(i=0;i<n;i++)
		scanf("%d",&s[i]);
		qsort(s,n,sizeof(s[0]),cmp);
		for(i=0;i<n;i++)
		{
			if(s[i]==s[i+1])
			t++;
			else
			{
				sum+=t;
				t=0;
			}
		}
		t=0;
		for(i=0;i<n;i++)
		{
			if(s[i]>n)
			t++;
		}
		printf("%d\n",sum>t?sum:t);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,i,j,t,sum;
	int s[5555];
	while(scanf("%d",&n)!=EOF)
	{
		t=0;sum=0;
		for(i=0;i<n;i++)
		scanf("%d",&s[i]);
		qsort(s,n,sizeof(s[0]),cmp);
		for(i=0;i<n;i++)
		{
			if(s[i]==s[i+1])
			t++;
			else
			{
				sum+=t;
				t=0;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    set<int> rr;
    set<int>::iterator it;
    int counter = 0;

    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;

        if (rr.find(temp) != rr.end())
        {
            counter++;
        }
        else{
            rr.insert(temp);
        }

    }
    cout << counter << endl;

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int a[5001];
    int counter = 0;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;
        a[temp] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0)
        {
            counter++;

        }
    }
    cout << counter << endl;

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include <memory>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int a[5001];
    int counter = 0;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;
        a[temp] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0)
        {
            counter++;

        }
    }
    cout << counter << endl;

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    set<int> rr;
    set<int>::iterator it;
    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;

        if (rr.find(temp) != rr.end())
        {
            counter++;
        }
        else{
            rr.insert(temp);
        }

    }
    cout << counter << endl;

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include <cstring>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int a[5001];
    int counter = 0;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;
        a[temp] = 1;
    }
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0)
        {
            counter++;

        }
    }
    cout << counter << endl;

    return 0;
}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>

using namespace std;

                                                                                #define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,n) for(int i = 1; i <= n; i++)
#define rep3(i,n) for(int i = n-1; i >= 0; i--)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+(0<((x)%(y))))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

void run() {

  /* entry point */
  int n;
  cin >> n;
  vi v(n);
  rep(i,n) { cin >> v[i]; }

  sort(all(v));
  int ans = 0;

  int flg[5010] = {};

  rep(i,n){
    if(flg[v[i]] != 0 || v[i] > n){
      ans++;
    }
    flg[v[i]] = 1;
  }

  cout << ans << endl;

}

#undef int

int main(int argc, char *argv[]) {

  #if 0
  if(online_judge){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a;
    bool vis[n+1];
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        cin>>a;
        vis[a]=1;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a;
    bool vis[5005];
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        cin>>a;
        vis[a]=1;
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i])cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


/*
Author: squiggly_lines
Date: 06/09/2014
Problem: 137B
*/

#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<string>
#include<deque>
#include<algorithm>
#include<cmath>
#include<utility>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<limits>

using namespace std;

#define pb push_back
#define umap unordered_map
#define uset unordered_set

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    std::ios::sync_with_stdio(false);
    //cin.tie(0);

    int n,i;
    cin >> n;
    uset<int> v;
    for(i = 0; i < n; i++){
        int k;
        cin >> k;
        v.insert(k);
    }

    cout << n-v.size() << '\n';
    return 0;

}


/*
Author: squiggly_lines
Date: 06/09/2014
Problem: 137B
*/

#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<string>
#include<deque>
#include<algorithm>
#include<cmath>
#include<utility>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<limits>

using namespace std;

#define pb push_back
#define umap unordered_map
#define uset unordered_set

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    std::ios::sync_with_stdio(false);
    //cin.tie(0);

    int n,i;
    cin >> n;
    vector<bool> v(n+1, false);
    int c = 0;
    for(i = 0; i < n; i++){
        int k;
        cin >> k;
        if(k > n){
            c++;
        }
        else if(v[k]){
            c++;
        }
        else{
            v[k] = true;
        }
    }

    cout << c << '\n';
    return 0;

}


#include <algorithm>
#include <queue>
#include <iostream>
#include <set>
#include <string>
#include <unordered_set>
#include <vector>

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define FORE(it,V) for(__typeof__(V.begin()) it = V.begin(); it != V.end(); ++it)

#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;

int main() {
	int n;
  std::cin >> n;
  std::unordered_set<int> perm;
  REP(i,n) {
    int x;
    std::cin >> x;
    perm.insert(x);
  }

  int result = 0;
  FOR(i,1,n) {
    if (perm.find(i) == perm.end()) {
      ++result;
    }
  }
  std::cout << result << std::endl;
}


//============================================================================
// Name        : Codeforces_16122011_B.cpp
// Author      : Afshin Arefi
// Version     :
// Copyright   : Copy Left
// Description : Codeforces 16 Dec 2011 - Question B
//============================================================================

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<set>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    char f[6000]={0};
    int ans=0;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        if(f[t])
        {
            ans++;
        }
        else
        {
            f[t]=1;
        }
        mx=max(mx,t);
    }
    int a=ans;
    for(int i=1;i<mx;i++)
    {
        if(f[i]==0)
        {
            if(a!=0)
                a--;
            else
            {
                ans++;
                mx--;
                while(f[mx]!=1)
                    mx--;
            }
        }
    }
    printf("%d",ans);
    return 0;
}


//============================================================================
// Name        : Codeforces_16122011_B.cpp
// Author      : Afshin Arefi
// Version     :
// Copyright   : Copy Left
// Description : Codeforces 16 Dec 2011 - Question B
//============================================================================

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<set>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    char f[6000]={0};
    int ans=0;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        if(f[t])
        {
            ans++;
        }
        else
        {
            f[t]=1;
        }
        mx=max(mx,t);
    }
    int a=ans;
    for(int i=0;i<mx;i++)
    {
        if(f[i]==0)
        {
            if(a!=0)
                a--;
            else
            {
                ans++;
                mx--;
                while(f[mx]!=1)
                    mx--;
            }
        }
    }
    printf("%d",ans);
    return 0;
}


//============================================================================
// Name        : Codeforces_16122011_B.cpp
// Author      : Afshin Arefi
// Version     :
// Copyright   : Copy Left
// Description : Codeforces 16 Dec 2011 - Question B
//============================================================================

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<set>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    char f[6000]={0};
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int t;
        scanf("%d",&t);
        if(f[t])
        {
            ans++;
        }
        else
        {
            f[t]=1;
        }
    }
    printf("%d",ans);
    return 0;
}


#include<iostream>

#include<cstdlib>

using namespace std;

void QuickSort(int l, int h, int a[])
{
    int i = l, j = h;

    int pivot = a[l + rand() % (h - l + 1)];

    while(i <= j)
    {
        while(a[i] < pivot) i++;

        while(a[j] > pivot) j--;

        if(i <= j)
        {
            int tmp;

            tmp = a[i]; a[i] = a[j]; a[j] = tmp;

            i++;

            j--;
        }
    }

    if(l < j) QuickSort(l, j, a);

    if(i < h) QuickSort(i, h, a);
}

int main()
{
    int n;

    cin >> n;

    int a[n + 1];

    for(int i = 1; i <= n; i++)
    cin >> a[i];

    QuickSort(1, n, a);

    int d = 0;

    a[0] = 0;

    for(int i = 1; i <= n; i++)
    if(a[i] != a[i - 1]) d++;

    cout << n - d;
}


#include<iostream>

#include<cstdlib>

using namespace std;

void QuickSort(int l, int h, int a[])
{
    int i = l, j = h;

    int pivot = a[l + rand() % (h - l + 1)];

    while(i <= j)
    {
        while(a[i] < pivot) i++;

        while(a[j] > pivot) j--;

        if(i <= j)
        {
            int tmp;

            tmp = a[i]; a[i] = a[j]; a[j] = tmp;

            i++;

            j--;
        }
    }

    if(l < j) QuickSort(l, j, a);

    if(i < h) QuickSort(i, h, a);
}

int main()
{
    int n;

    cin >> n;

    int a[n + 1];

    for(int i = 1; i <= n; i++)
    cin >> a[i];

    QuickSort(1, n, a);

    int d = 0;

    a[0] = 0;

    for(int i = 1; i <= n; i++)
    if(a[i] != a[i - 1] && a[i] >= 1 && a[i] <= n) d++;

    cout << n - d;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <bitset>
#include <string.h>
using namespace std;

typedef long long int64;
#define SIZE(a) ((int)a.size())
#define LENGTH(a) ((int)a.length())
#define MOD 256
#define MAX 60

struct integer_utilis {
	static bool power_of_two(int n) {
		return (n & (n - 1)) == 0;
	}

	static int power_of_prime_in_factorial(int x, int prime) {
		int r = 0;
		while (x) {
			r += x / prime;
			x /= prime;
		}
		return r;
	}

	static vector<int> generat_primes(int n) {
		int i, j;
		vector<int> primes(1, 2);
		for (i = 3; i <= n; i += 2) {
			for (j = 0; primes[j] * primes[j] <= i; j++) {
				if (!(i % primes[j])) break;
			}
			if (primes[j] * primes[j] > i)
				primes.push_back(i);
		}
		return primes;
	}

	static void fill_ncr(int size, int64 ncr[][MAX]) {
		for (int i = 0; i < size; ++i)
			ncr[i][0] = ncr[i][i] = 1;
		for (int i = 1; i < size; ++i)
			for (int j = 1; j < i; ++j)
				ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
	}

	static void fill_prime(int n, bool prime[]) {
		prime[1] = false;
		for (int i = 2; i * i <= n; ++i)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
	}

	static int negative_mod(int a, int b) {
		return (a % b + b) % b;
	}

	static int round(double x) {
		int ret = x;
		ret += (x - double(int(x)) >= 0.5);
		return ret;
	}

	template<class T> static bool is_prime(const T& n) {
		if (n == 2) return true;
		if (!(n % 2) || n == 1) return false;
		for (T i = 3; i * i <= n; i += 2)
			if (!(n % i)) return false;
		return true;
	}

	template<class T> static T gcd(T a, T b) {
		while (b > 0) {
			T t = a % b;
			a = b;
			b = t;
		}
		return a;
	}

	template<class T> static T lcm(T a, T b) {
		return a / gcd<T>(a, b) * b;
	}

	template<class T> static T abs(T a) {
		return a < 0 ? -a : a;
	}

	template<class T> static T power(T b, int p) {
		T x(1), y(b);
		for (; p > 0; p >>= 1) {
			if (p % 2)
				x *= y;
			y *= y;
		}
		return x;
	}
};

struct Interval {
	int64 s, e;
	Interval() {}
	Interval(int64 s, int64 e) {
		this->s = s;
		this->e = e;
	}
	bool operator < (Interval i) {
		return this->e - this->s < i.e - i.s;
	}
};

struct test {
	static void print(vector<Interval> v) {
		for (int i = 0; i < SIZE(v); ++i)
			cout << v[i].s << " " << v[i].e << endl;
	}
};

int main() {
	//freopen("in.txt", "r", stdin);
	for (int n; cin >> n;) {
		int m[5005], arr[5005];
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; ++i) {
			cin >> arr[i];
			m[arr[i]]++;
		}
		int res = 0;
		for (int i = 1; i <= n; ++i)
			if (!m[i]) ++res;
		cout << res << endl;
	}
	return 0;
}


#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <iostream>
#include <limits.h>
using namespace std;

typedef long long int64;
#define SIZE(a) ((int)a.size())
#define LENGTH(a) ((int)a.length())
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define MOD 256
#define MAX 60

struct integer_utilis {
	int nextChoose(int x) {
		int c = x & -x, r = x + c;
		return (((r ^ x) >> 2) / c) | r;
	}

	static bool leap(int year) {
		if (year % 100 == 0 && year % 400 == 0)
				return true;
		if (year % 4 == 0) return true;
		return false;
	}

	static int days_in_month(int month, int year) {
		if (month == 4 || month == 6 || month == 9 || month == 11)
			return 30;
		if (month == 2) return 28 + integer_utilis::leap(year);
		return 31;
	}

	static bool power_of_two(int n) {
		return (n & (n - 1)) == 0;
	}

	static int power_of_prime_in_factorial(int x, int prime) {
		int r = 0;
		while (x) {
			r += x / prime;
			x /= prime;
		}
		return r;
	}

	template<class T> static vector<T> generat_primes(T n) {
		T i, j;
		vector<T> primes(1, 2);
		for (i = 3; i <= n; i += 2) {
			for (j = 0; primes[j] * primes[j] <= i; j++) {
				if (!(i % primes[j])) break;
			}
			if (primes[j] * primes[j] > i)
				primes.push_back(i);
		}
		return primes;
	}

	static void fill_ncr(int size, int64 ncr[][MAX]) {
		for (int i = 0; i < size; ++i)
			ncr[i][0] = ncr[i][i] = 1;
		for (int i = 1; i < size; ++i)
			for (int j = 1; j < i; ++j)
				ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
	}

	static void fill_prime(int n, bool prime[]) {
		prime[1] = false;
		for (int i = 2; i * i <= n; ++i)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
	}

	static int negative_mod(int a, int b) {
		return (a % b + b) % b;
	}

	static int round(double x) {
		int ret = x;
		ret += (x - double(int(x)) >= 0.5);
		return ret;
	}

	template<class T> static bool is_prime(const T& n) {
		if (n == 2) return true;
		if (!(n % 2) || n == 1) return false;
		for (T i = 3; i * i <= n; i += 2)
			if (!(n % i)) return false;
		return true;
	}

	template<class T> static T gcd(T a, T b) {
		while (b > 0) {
			T t = a % b;
			a = b;
			b = t;
		}
		return a;
	}

	template<class T> static T lcm(T a, T b) {
		return a / gcd<T>(a, b) * b;
	}

	template<class T> static T abs(T a) {
		return a < 0 ? -a : a;
	}

	template<class T> static T power(T b, int p) {
		T x(1), y(b);
		for (; p > 0; p >>= 1) {
			if (p % 2)
				x *= y;
			y *= y;
		}
		return x;
	}
};

struct test {};

int arr[5005];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
#endif
	for (int n; cin >> n;) {
		int m[5005];
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; ++i) {
			cin >> arr[i];
			m[arr[i]]++;
		}
		int res = 0;
		for (int i = 1; i < 5001; ++i) {
			if (m[i] > 1) {
				res += (m[i] - 1);
				continue;
			}
			if (i > n) if (m[i]) ++res;
		}
		cout << res << endl;
	}
	return 0;
}


#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <iostream>
#include <limits.h>
using namespace std;

typedef long long int64;
#define SIZE(a) ((int)a.size())
#define LENGTH(a) ((int)a.length())
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define MOD 256
#define MAX 60

struct integer_utilis {
	int nextChoose(int x) {
		int c = x & -x, r = x + c;
		return (((r ^ x) >> 2) / c) | r;
	}

	static bool leap(int year) {
		if (year % 100 == 0 && year % 400 == 0)
				return true;
		if (year % 4 == 0) return true;
		return false;
	}

	static int days_in_month(int month, int year) {
		if (month == 4 || month == 6 || month == 9 || month == 11)
			return 30;
		if (month == 2) return 28 + integer_utilis::leap(year);
		return 31;
	}

	static bool power_of_two(int n) {
		return (n & (n - 1)) == 0;
	}

	static int power_of_prime_in_factorial(int x, int prime) {
		int r = 0;
		while (x) {
			r += x / prime;
			x /= prime;
		}
		return r;
	}

	template<class T> static vector<T> generat_primes(T n) {
		T i, j;
		vector<T> primes(1, 2);
		for (i = 3; i <= n; i += 2) {
			for (j = 0; primes[j] * primes[j] <= i; j++) {
				if (!(i % primes[j])) break;
			}
			if (primes[j] * primes[j] > i)
				primes.push_back(i);
		}
		return primes;
	}

	static void fill_ncr(int size, int64 ncr[][MAX]) {
		for (int i = 0; i < size; ++i)
			ncr[i][0] = ncr[i][i] = 1;
		for (int i = 1; i < size; ++i)
			for (int j = 1; j < i; ++j)
				ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
	}

	static void fill_prime(int n, bool prime[]) {
		prime[1] = false;
		for (int i = 2; i * i <= n; ++i)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
	}

	static int negative_mod(int a, int b) {
		return (a % b + b) % b;
	}

	static int round(double x) {
		int ret = x;
		ret += (x - double(int(x)) >= 0.5);
		return ret;
	}

	template<class T> static bool is_prime(const T& n) {
		if (n == 2) return true;
		if (!(n % 2) || n == 1) return false;
		for (T i = 3; i * i <= n; i += 2)
			if (!(n % i)) return false;
		return true;
	}

	template<class T> static T gcd(T a, T b) {
		while (b > 0) {
			T t = a % b;
			a = b;
			b = t;
		}
		return a;
	}

	template<class T> static T lcm(T a, T b) {
		return a / gcd<T>(a, b) * b;
	}

	template<class T> static T abs(T a) {
		return a < 0 ? -a : a;
	}

	template<class T> static T power(T b, int p) {
		T x(1), y(b);
		for (; p > 0; p >>= 1) {
			if (p % 2)
				x *= y;
			y *= y;
		}
		return x;
	}
};

struct test {};

int arr[5005];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
#endif
	for (int n; cin >> n;) {
		map<int, int> m;
		for (int i = 0; i < n; ++i) {
			cin >> arr[i];
			m[arr[i]]++;
		}
		int res = 0;
		FOREACH(it, m) if (it->second > 1) res += (it->second - 1);
		cout << res << endl;
	}
	return 0;
}


#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <bitset>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <iostream>
#include <limits.h>
using namespace std;

typedef long long int64;
#define SIZE(a) ((int)a.size())
#define LENGTH(a) ((int)a.length())
#define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define MOD 256
#define MAX 60

struct integer_utilis {
	int nextChoose(int x) {
		int c = x & -x, r = x + c;
		return (((r ^ x) >> 2) / c) | r;
	}

	static bool leap(int year) {
		if (year % 100 == 0 && year % 400 == 0)
				return true;
		if (year % 4 == 0) return true;
		return false;
	}

	static int days_in_month(int month, int year) {
		if (month == 4 || month == 6 || month == 9 || month == 11)
			return 30;
		if (month == 2) return 28 + integer_utilis::leap(year);
		return 31;
	}

	static bool power_of_two(int n) {
		return (n & (n - 1)) == 0;
	}

	static int power_of_prime_in_factorial(int x, int prime) {
		int r = 0;
		while (x) {
			r += x / prime;
			x /= prime;
		}
		return r;
	}

	template<class T> static vector<T> generat_primes(T n) {
		T i, j;
		vector<T> primes(1, 2);
		for (i = 3; i <= n; i += 2) {
			for (j = 0; primes[j] * primes[j] <= i; j++) {
				if (!(i % primes[j])) break;
			}
			if (primes[j] * primes[j] > i)
				primes.push_back(i);
		}
		return primes;
	}

	static void fill_ncr(int size, int64 ncr[][MAX]) {
		for (int i = 0; i < size; ++i)
			ncr[i][0] = ncr[i][i] = 1;
		for (int i = 1; i < size; ++i)
			for (int j = 1; j < i; ++j)
				ncr[i][j] = ncr[i - 1][j - 1] + ncr[i - 1][j];
	}

	static void fill_prime(int n, bool prime[]) {
		prime[1] = false;
		for (int i = 2; i * i <= n; ++i)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
	}

	static int negative_mod(int a, int b) {
		return (a % b + b) % b;
	}

	static int round(double x) {
		int ret = x;
		ret += (x - double(int(x)) >= 0.5);
		return ret;
	}

	template<class T> static bool is_prime(const T& n) {
		if (n == 2) return true;
		if (!(n % 2) || n == 1) return false;
		for (T i = 3; i * i <= n; i += 2)
			if (!(n % i)) return false;
		return true;
	}

	template<class T> static T gcd(T a, T b) {
		while (b > 0) {
			T t = a % b;
			a = b;
			b = t;
		}
		return a;
	}

	template<class T> static T lcm(T a, T b) {
		return a / gcd<T>(a, b) * b;
	}

	template<class T> static T abs(T a) {
		return a < 0 ? -a : a;
	}

	template<class T> static T power(T b, int p) {
		T x(1), y(b);
		for (; p > 0; p >>= 1) {
			if (p % 2)
				x *= y;
			y *= y;
		}
		return x;
	}
};

struct test {};

int arr[5005];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
#endif
	for (int n; cin >> n;) {
		int m[5005];
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; ++i) {
			cin >> arr[i];
			m[arr[i]]++;
		}
		int res = 0;
		for (int i = 1; i < 5001; ++i) {
			if (m[i] > 1) {
				res += (m[i] - 1);
				continue;
			}
			if (i > n) if (m[i]) res += m[i];
		}
		cout << res << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a,nbr(0);
    map<int,int> A;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a;
        A[a]++;
    }
    for(int i=1;i<=n;i++){
        nbr += (A[i] > 1) ? A[i]-1 : 0;
    }
    cout << nbr << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,a,nbr(0);
    map<int,int> A;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a;
        A[a]++;
    }
    for(int i=1;i<=n;i++){
        nbr += (A[i]==0) ? 1 : 0;
    }
    cout << nbr << endl;
    return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define F first
#define S second
#define max(a,b) (a>b?a:b)
#define mid(a,b) (a<b?a:b)

typedef long long ll;
using namespace std;

const ll N = 1e5 + 9;
ll n, ans;
ll a[N];

int main()
{_
    cin >> n;
    rep(i, n) {
        ll x;
        cin >> x;
        a[x]++;
    }
    for (int i = 1; i <= n; i++)
        if (!a[i])
            ans++;
    cout << ans;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j,i,n;
    char b[105];
    scanf("%d",&t);
    fflush(stdin);
    for (i=0; i<t; i++)
    {
        scanf("%s",b);
        n=strlen(b);
        for (j=0; j<(n-2); j+=2)
        {
            printf("%c",b[j]);
        }
     printf("%c%c\n",b[n-2],b[n-1]);

    }

}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j,i,count=0,n;
    char b[105],a[105];
    scanf("%d",&t);
    for (i=0; i<t; i++)
    {
        count=0;
        fflush(stdin);
        scanf("%s",b);
        n=strlen(b);
        for (j=0; j<(n-2); j+=2)
        {
            printf("%c",b[j]);
        }
     printf("%c%c\n",b[n-2],b[n-1]);

    }

}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j,i,count=0,n;
    char b[105],a[105];
    scanf("%d",&t);
    fflush(stdin);
    for (i=0; i<t; i++)
    {
        count=0;
        scanf("%s",b);
        n=strlen(b);
        for (j=0; j<(n-2); j+=2)
        {
            printf("%c",b[j]);
        }
     printf("%c%c\n",b[n-2],b[n-1]);

    }

}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,i,j,l;
    char s[1000][1000];
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%s",s[i]);
    }
    for(i=0;i<t;i++)
    {
        l = strlen(s[i]);
        for(j=0;j<l;j = j+2)
        {
            printf("%c",s[i][j]);
        }
        if(l%2==0)
        {
            printf("%c",s[i][l-1]);
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>
void main()
{
    int t,i,l,j;
    char s[100000];
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%s",s);
        l = strlen(s);
        for(j=0;j<l;j=j+2)
        {
            printf("%c",s[j]);
        }
        printf("\n");
    }
}


#include<stdio.h>
#include<string.h>
void main()
{
    int t,i,l,j;
    char s[100000];
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%s",s);
        l = strlen(s);
        for(j=0;j<l;j = j+2)
        {
            printf("%c",s[j]);
        }
        if(l%2==0)
        {
            printf("%c",s[l-1]);
        }
        printf("\n");
    }
}


#include<stdio.h>
#include<string.h>

int main()
{
    int t,i,a,b;
    char string[100];
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%s",string);
        a=strlen[string];
        printf("%c",string[0]);
        for(b=1;b<a-1;b=b+2)
        {
            printf("%c",string[b]);
        }
        printf("%c\n",string[a-1]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    int t,i,a,b;
    char string[100];
    scanf("%d",&t);
    for(i=1;i<=t;i++)
    {
        scanf("%s",string);
        a=strlen(string);
        printf("%c",string[0]);
        for(b=1;b<a-1;b=b+2)
        {
            printf("%c",string[b]);
        }
        printf("%c\n",string[a-1]);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;i++){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c%c",a[i],a[i+1]);
                                        i=i+2;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[100];
                    scanf("%s",&a);
                    int n1=strlen(a);
                    for(int i=1;i<=n1; ){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");

          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c2;
                    scanf("%s",&a);
                    c2=strlen(a);
                    for(int i=0;i<=2c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;i++){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c%c",a[i],a[i+1]);
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<=c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c2;
                    scanf("%s",&a);
                    c2=strlen(a);
                    for(int i=0;i<=c2;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;i++){
                              if(a[i]!=a[i+1]){
                                        printf("%c",a[i]);
                                       // i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=1;i<=c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;i++){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<=c;i++){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;i++){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        //i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c1;
                    scanf("%s",&a);
                    c1=strlen(a);
                    for(int i=0;i<=c1;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        if(i==(c-2)){
                                                  printf("%c",a[i+1]);
                                        }
                                        i=i+2;

                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main()
          int n;
          scanf("%d",&n);
          while(n--){
                    char a[101];
                    int c;
                    scanf("%s",&a);
                    c=strlen(a);
                    for(int i=0;i<c;){
                              if(a[i]==a[i+1]){
                                        printf("%c",a[i]);
                                        i=i+2;
                              }
                              else{
                                        printf("%c",a[i]);
                                        i=i+1;
                              }
                    }
                    printf("\n");
          }
          return 0;
}


#include<stdio.h>
#include<string.h>
int main(){
char a[100];
int i,t,l;
scanf("%d",&t);
while(t!=0){
scanf("%s",a);
l=strlen(a);
for(i=0;i<l;i++){
if(i%2==1||i==0){
printf("%c",a[i]);
}
}
printf("\n");
t--;
}
}


#include<stdio.h>
#include<string.h>
int main(){
char a[100];
int i,t,l;
scanf("%d",&t);
while(t!=0){
scanf("%s",a);
l=strlen(a);
if(l<=2){
printf("%s",a);
}
else{
for(i=0;i<=l;i=i+2){
printf("%c",a[i]);
}
printf("%c",a[l-1]);
}
printf("\n");
t--;
}
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct arry
{
    char *ch;
};
char *original(char *arr,int l)
{
 int i,k=0;
 char *c=(char *)malloc(100*sizeof(char));
 c[k++]=arr[0];
 for(i=2;i<l && arr[i]!='\0';i+=2)
 {
     c[k++]=arr[i];
 }
 c[k++]=arr[l-1];
 return c;
 free(c);
}

int main()
{

    int t;
    scanf("%d",&t);
    struct arry o[t];
    int i;
    for(i=0;i<t;i++)
    {
      char *b=(char *)malloc(100*sizeof(char));
      scanf("%s",b);
      int l=strlen(b);
      if(l<=2)
        o[i].ch=b;
      else
      o[i].ch=original(b,l);
    }
    for(i=0;i<t;i++)
        printf("%s\n",o[i].ch);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct arry
{
    char *ch;
};
char *original(char *arr,int l)
{
 int i,k=0;
 char *c=(char *)malloc(100*sizeof(char));
 for(i=0;i<l && arr[i]!='\0';i+=2)
 {
     c[k++]=arr[i];
 }
 c[k++]=arr[l-1];
 return c;
 free(c);
}

int main()
{

    int t;
    scanf("%d",&t);
    struct arry o[t];
    int i;
    for(i=0;i<t;i++)
    {
      char *b=(char *)malloc(100*sizeof(char));
      scanf("%s",b);
      int l=strlen(b);
      if(l<=2)
        o[i].ch=b;
      else
      o[i].ch=original(b,l);
    }
    for(i=0;i<t;i++)
        printf("%s\n",o[i].ch);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct arry
{
    char *ch;
};
char *original(char *arr,int l)
{
 int i,k=0;
 char *c=(char *)malloc(100*sizeof(char));
 c[k++]=arr[0];
 for(i=2;i<l;i+=2)
 {
     c[k++]=arr[i];
 }
 c[k++]=arr[l-1];
 return c;
 free(c);
}

int main()
{

    int t;
    scanf("%d",&t);
    struct arry o[t];
    int i;
    for(i=0;i<t;i++)
    {
      char *b=(char *)malloc(100*sizeof(char));
      scanf("%s",b);
      int l=strlen(b);
      if(l<=2)
        o[i].ch=b;
      else
      o[i].ch=original(b,l);
    }
    for(i=0;i<t;i++)
        printf("%s\n",o[i].ch);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct arry
{
    char *ch;
};
char *original(char *arr,int l)
{
 int i,k=0;
 char *c=(char *)malloc(100*sizeof(char));
 c[k++]=arr[0];
 for(i=2;i<l-2 && arr[i]!='\0';i+=2)
 {
     c[k++]=arr[i];
 }
 c[k++]=arr[l-1];
 return c;
 free(c);
}

int main()
{

    int t;
    scanf("%d",&t);
    struct arry o[t];
    int i;
    for(i=0;i<t;i++)
    {
      char *b=(char *)malloc(100*sizeof(char));
      scanf("%s",b);
      int l=strlen(b);
      if(l<=2)
        o[i].ch=b;
      else
      o[i].ch=original(b,l);
    }
    for(i=0;i<t;i++)
        printf("%s\n",o[i].ch);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct arry
{
    char *ch;
};
char *original(char *arr,int l)
{
 int i,k=0;
 char *c=(char *)malloc(100*sizeof(char));
 for(i=0;arr[i]!='\0';i+=2)
 {
     c[k++]=arr[i];
 }
 c[k++]=arr[l-1];
 c[k++]='\0';
 return c;
 free(c);
}

int main()
{

    int t;
    scanf("%d",&t);
    struct arry o[t];
    int i;
    for(i=0;i<t;i++)
    {
      char *b=(char *)malloc(100*sizeof(char));
      scanf("%s",b);
      int l=strlen(b);
      if(l<=2)
        o[i].ch=b;
      else
      o[i].ch=original(b,l);
    }
    for(i=0;i<t;i++)
         printf("%s\n",o[i].ch);

    return 0;
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<=n;i++){
    char s[100];
    gets(s);
    int l;
    l=strlen(s);
    for(int i=0;i<l;i++)
    {
      if(s[i]==s[i+1])
      {
         i=i+1;
      }
      printf("%c",s[i]);
    }
    printf("\n");
}
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int l;
        char s[100];
        scanf("%s",s);
        l=strlen(s);
        printf("%c",s[0]);
        for(int i=0;i<l-1;i++)
        {
            i=i+1;
            printf("%c",s[i]);
        }

        printf("\n");

    }
}


#include<stdio.h>
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<=n;i++){
    char s[100];
    gets(s);
    int l;
    l=strlen(s);
    for(int i=0;i<l;i++)
    {

       if(s[i]==s[i+2])
      {
        i=i+1;
      }
      else if(s[i]==s[i+1])
      {
          i=i+1;
      }
      printf("%c",s[i]);
    }
    printf("\n");
}
}


#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int l;
        char s[100];
        scanf("%s",s);
        l=strlen(s);
        printf("%c",s[0]);
        for(int i=0;i<l-1;i++)
        {
            i=i+1;
            printf("%c",s[i]);
        }
        printf("%c",s[l]);
        printf("\n");

    }
}


#include<stdio.h>
#include<string.h>
main()
{
    int i,l,n,j;
    scanf("%d",&n);
    getchar();
    char s[100],t[100];
    for(i=0;i<n;i++){
            scanf("%s",&s);
            getchar();

            l = strlen(s);
            for(i=0;i<l-2;i++){
                if(i%2==0){
                    printf("%c",s[i]);
                }

            }

            printf("%c%c\n",s[l-2],s[l-1]);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    int i,l,n,j;
    scanf("%d",&n);

    char s[100],t[100];
    for(i=0;i<n;i++){
            scanf("%s",&s);

            l = strlen(s);
            for(j=0;j<l;j++){
                if(j%2==0){
                    printf("%c",s[j]);
                }

            }

           // printf("%c%c\n",s[l-2],s[l-1]);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    int i,l,n,j;
    scanf("%d",&n);

    char s[100],t[100];
    for(i=0;i<n;i++){
            scanf("%s",&s);

            l = strlen(s);
            for(j=0;j<l-2;j++){
                if(j%2==0){
                    printf("%c",s[j]);
                }

            }

            printf("%c%c\n",s[l-2],s[l-1]);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    int i,l,n,j;
    scanf("%d",&n);
    char s[100],t[100];
    for(i=0;i<n;i++){
            scanf("%s",&s);

            l = strlen(s);
            for(i=0;i<l-2;i++){
                if(i%2==0){
                    printf("%c",s[i]);
                }

            }

            printf("%c%c\n",s[l-2],s[l-1]);

    }

    return 0;
}


#include<stdio.h>
#include<string.h>
main()
{
    int i,l,n,j;
    scanf("%d",&n);
    getchar();
    char s[100],t[100];
    for(i=0;i<n;i++){
            scanf("%s",&s);
            getchar();

            l = strlen(s);
            for(j=0;j<l-2;j++){
                if(j%2==0){
                    printf("%c",s[j]);
                }

            }

            printf("%c%c\n",s[l-2],s[l-1]);

    }

    return 0;
}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0';i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag-=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0',i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int t,a,n,i;

a=1;
    scanf("%d",&t);
    while(a<=t)
    {
        int b[n];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++)
    {
        printf("%d",b[i]);
        printf("%d",b[i+1]);
    }
    }

}


#include<stdio.h>
int main()
{
    int;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0',i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag-=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0',i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0',i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


include<stdio.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char ch[100],i,flag=0,j;
        scanf("%s",ch);
        for(i=0;ch[i]!='\0',i++)
        {
            flag++;

        }
        if(flag<=2)
        {
            printf("%s\n",ch);

        }
        else
        {
            for(j=0;j<flag-1;j=j+2)
            {
                printf("%c",ch[j]);

            }
            printf("%c\n",ch[flag-1]);

        }

    }
    return 0;

}


#include<stdio.h>
int main()
{
    int t,a,n,i;
    int b[n];
a=1;
    scanf("%d",&t);
    while(a<=t)
    {
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        printf("%d",a[i]);
        printf("%d",a[i+1]);
    }
    }

}


#include<stdio.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char s[100];
        scanf("%s",s);
        int i;
        printf("%c",s[0]);
        printf("%c",s[1]);
        for(i = 3; s[i] != '\0';i++){
            if(i % 2 != 0){
                printf("%c",s[i]);
            }
        }
        printf("\n");
    }
    return 0;

}


#include<stdio.h>
#include<stdio.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char s[100];
        scanf("%s",s);
        int i;
        printf("%c",s[0]);
        printf("%c",s[1]);
        if(strlen(s) == 2){
            return 0;
        }
        for(i = 3; s[i] != '\0';i++){
            if(i % 2 != 0){
                printf("%c",s[i]);
            }
        }
        printf("\n");
    }
    return 0;

}


#include<stdio.h>
#include<stdio.h>
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char s[100];
        scanf("%s",s);
        int i;
        printf("%c",s[0]);
        printf("%c",s[1]);
        if(strlen(s) == 2){
            printf("\n");
        } else {
            for(i = 3; s[i] != '\0';i++){
                if(i % 2 != 0){
                    printf("%c",s[i]);
                }
            }
        }
        printf("\n");
    }
    return 0;

}


#include <stdio.h>
#include <string.h>

int main()
{
    int t,i;
    char b[100];
    scanf("%d",&t);

    for(int x=0;x<t;x++)
    {
        char a[100]={};
        int j=1;
        scanf("%s",b);
        if(strlen(b)==2)
        printf("%s",b);
        else
        {
            a[0]=b[0];
            for(i=1;i<strlen(b)-2;i=i+2)
            {
                a[j]=b[i];
                j++;
            }
            a[j]=b[strlen(b)-1];
            printf("%s",a);
        }
        printf("\n");
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n,l;
    char a[105];
    while(scanf("%d",&n)!=EOF){
    for(i=1;i<=n;i++){
      scanf("%s",&a);
      j=strlen(a);
      for(l=0;l<j;l++){
        if(l%2==0||l==j-1){printf("%c",a[l]);}
        }printf("\n");
      }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n,l;
    char a[105];
    while(scanf("%d",&n)!=EOF){
    for(i=1;i<=n;i++){
      scanf("%s",&a);
      j=strlen(a);
      printf("%c%c",a[0],a[1]);
      for(l=3;l<j;l=l+2){
        printf("%c",a[l]);
        }printf("\n");
      }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n,l;
    char a[105];
    while(scanf("%d",&n)!=EOF){
    for(i=1;i<n;i++){
      scanf("%s",&a);
      j=strlen(a);
      printf("%c%c",a[0],a[1]);
      for(l=3;l<j;l=l+2){
        printf("%c",a[l]);
        }printf("\n");
      }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,n,l;
    char a[105];
    while(scanf("%d",&n)!=EOF){
    for(i=1;i<n;i++){
      scanf("%s",&a);
      j=strlen(a);
      for(l=0;l<j;l++){
        if(l%2==0||l==j-1){printf("%c",a[l]);}
        }printf("\n");
      }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[1000];
     char s1[100];
    int t,l,i,j;

    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+1,j++)
       {
           s1[j]=s[i];
    if(s[i]==s[i+1])
{
         i++;
}

}
printf("%s\n",s1);
}
printf ("\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[1000];
     char s1[1000];
    int t,l,i,j;
    char b;
    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+1,j++)
       {
           s1[j]=s[i];
    if(s[i]=s[i+1])
{
         i++;
}
b=s[i+1];
}
printf("%s%c\n",s1,b);
}
printf ("\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[1000];
     char s1[100];
    int t,l,i,j;
    char b;
    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+1,j++)
       {
           s1[j]=s[i];
    if(s[i]=s[i+1])
{
         i++;
}
b=s[i+1];
}
printf("%s%c\n",s1,b);
}
printf ("\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[100];

];
     char s1[100];
    int t,l,i,j;
    char b;
    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+1,j++)
       {
           s1[j]=s[i];
    if(s[i]=s[i+1])
{
         i++;
}
b=s[i+1];
}
printf("%s%c\n",s1,b);
}
printf ("\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[1000];
     char s1[100];
     char b;
    int t,l,i,j;

    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+2,j++)
       {
           s1[j]=s[i];

         b=s[l-1];
}
printf("%s%c\n",s1,b);
}
printf ("\n");
}
return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
     char s[1000];
     char s1[100];
    int t,l,i,j;

    scanf("%d",&t);
    while(t--)
      {
         scanf("%s",&s);
         l=strlen(s);
         if(l==2)
         {
             printf("%s\n",s);
          }
         else{
            for(i=0,j=0;i<l,j<l;i=i+1,j++)
       {
           s1[j]=s[i];
    if(s[i]==s[i+1])
{
         i++;
}

}
printf("%s\n",s1);
}
printf ("\n");
}

return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);

        if(n!=2){
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1; i<n-1;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
        }
        stringOutput[i]=stringInput[n-1];

        printf("%s\n",stringOutput);
        }

        else if(n==2) printf("%s\n",stringInput);

    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);

        if(n!=2){
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1;;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
            if(j>=n-1) break;
        }
        stringOutput[i+1]=stringInput[n-1];

        /*printf("%s\n",stringOutput);*/
        for(int i2=0; i2<=i+1;i2++) printf("%c",stringOutput[i2]);
        }

        else if(n==2) printf("%s\n",stringInput);

    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1; i<n-1;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
        }
        stringOutput[i]=stringInput[n-1];

        printf("%s\n",stringOutput);

    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);

        if(n!=2){
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1;;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
            if(j>=n-1) break;
        }
        stringOutput[i+1]=stringInput[n-1];

        /*printf("%s\n",stringOutput);*/
        for(int i2=0; i2<=i+1;i2++) printf("%c",stringOutput[i2]);
        printf("\n");
        }

        else if(n==2) printf("%s\n",stringInput);

    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    char stringInput[100],stringOutput[100];
    while(t--){
        scanf("%s",stringInput);
        int n = strlen(stringInput);
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1; i<n-1;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
        }
        stringOutput[i]=stringInput[n-1];

        printf("%s",stringOutput);
    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);

        if(n!=2){
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1;;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
            if(j>=n-1) break;
        }
        stringOutput[i]=stringInput[n-1];

        printf("%s\n",stringOutput);
        }

        else if(n==2) printf("%s\n",stringInput);

    }
return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        char stringInput[100],stringOutput[100];
        scanf("%s",stringInput);
        int n = strlen(stringInput);

        if(n!=2){
        stringOutput[0]=stringInput[0];
        int j=1, i;
        for(i=1;;i++){
            stringOutput[i]=stringInput[j];
            j=j+2;
            if(j>=n-1) break;
        }
        stringOutput[i+1]=stringInput[n-1];

        printf("%s\n",stringOutput);
        }

        else if(n==2) printf("%s\n",stringInput);

    }
return 0;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 1];
  uint8_t len;
  uint8_t i;
  scanf ("%" SCNu16 "\n", &t);
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 2];
  uint8_t len;
  uint8_t i;
  uint16_t nTC;
  scanf ("%" SCNu16 "\n", &t);
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          if (t == 1000 - 509)
            {
              printf ("%ld", strlen (b));
              return EXIT_SUCCESS;
            }
          ++nTC;
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 1];
  uint8_t len;
  uint8_t i;
  uint16_t nTC;
  scanf ("%" SCNu16 "\n", &t);
  nTC = 1;
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          if (nTC == 3)
            {
              printf ("%s", b);
            }
          ++nTC;
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 1];
  uint8_t len;
  uint8_t i;
  uint16_t nTC;
  scanf ("%" SCNu16 "\n", &t);
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          if (t == 1000 - 509)
            {
              printf ("%s", b);
              return EXIT_SUCCESS;
            }
          ++nTC;
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 2];
  uint8_t len;
  uint8_t i;
  scanf ("%" SCNu16 "\n", &t);
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint8_t t;
  char b[MAX_LEN + 1];
  uint8_t len;
  uint8_t i;
  scanf ("%" SCNu8 "\n", &t);
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


/*
 *        File: main.c
 * Description: Codeforce problemset 1267A - Short Substrings.
 *  Created on: Aug 15 2020 22:11 +0700
 *      Author: tbtt
 */
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

#define MAX_LEN 100

int
main (void)
{
#ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
#endif
  uint16_t t;
  char b[MAX_LEN + 1];
  uint8_t len;
  uint8_t i;
  uint16_t nTC;
  scanf ("%" SCNu16 "\n", &t);
  nTC = 1;
  while (t--)
    {
      if (fgets (b, sizeof (b), stdin))
        {
          if (t > 4 && nTC == 3)
            {
              printf ("%s", b);
            }
          ++nTC;
          len = (uint8_t) strlen (b) - 1;
          printf ("%c", b[0]);
          for (i = 1; i < len; i += 2)
            {
              if (b[i] == b[i + 1])
                {
                  printf ("%c", b[i]);
                }
            }
          printf ("%c", b[len - 1]);
        }
      printf ("\n");
    }
  return EXIT_SUCCESS;
}


#include<stdio.h>

int main()
{
    char S[101];
    int t,count;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%s",S);
        for(int j=0;S[j]!='\0';j+=2)
        {
            if(S[j+1]=='\0')
            {
                printf("%c",S[j]);
                break;
            }
            else if(S[j+2]=='\0')
            {
                printf("%c%c",S[j],S[j+1]);
                break;
            }
            else
            {
                printf("%c",S[j]);
            }
        }
        printf("\n");
    }
    return 0;
}


#include<stdio.h>

int main()
{
    char S[101],prev;
    int t,count;
    scanf("%d",&t);
    for(int i=0;i<t;i++)
    {
        scanf("%s",S);
        printf("%c",S[0]);
        prev = S[0];
        count = 1;
        for(int j=1;S[j]!='\0';j++)
        {
            if(S[j+1]=='\0')
            {
                printf("%c\n",S[j]);
                break;
            }
            else if(prev==S[j])
            {
                count++;
                if((count%2)==0)
                {
                    printf("%c",S[j]);
                }
            }
            else
            {
                count = 1;
                prev = S[j];
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j;scanf("%d",&t);
    while(t>0)
    {
        int i,x,n,len;
        char str1[100];
        scanf("%s",&str1);
        len=strlen(str1);char str2[100];

        for(i=0; i<=(len/2)-1; i++) {
            str2[i]=str1[i*2];}
        str2[(len-1)/2+1]=str1[len-1];
        printf("%s\n",str2);
        t--;
  }
}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j;scanf("%d",&t);
    while(t>0)
    {
        int i,x,n,len;
        char str1[100];
        scanf("%s",&str1);
        len=strlen(str1);char str2[100];

        for(i=0; i<=(len-1)/2; i++) {
            str2[i]=str1[i*2];}
        str2[(len-1)/2+1]=str1[len-1];
        printf("%s\n",str2);
        t--;
  }
}


#include<stdio.h>
#include<string.h>
int main()
{
    int t,j;scanf("%d",&t);
    while(t>0)
    {
        int i,x,n,len;
        char str1[100];
        scanf("%s",&str1);
        len=strlen(str1);char str2[100];

        for(i=0; i<=(len-1)/2; i++) {
            str2[i]=str1[i*2];}
        str2[(len-1)/2+1]=str1[len-1];
        str2[(len-1)/2+2]='\0';
        printf("%s\n",str2);
        t--;
  }
}


 #include<stdio.h>
#include<string.h>
int main()
{
    int t,j;scanf("%d",&t);
    while(t>0)
    {
        int i,x,n,len;
        char str1[100];
        scanf("%s",&str1);
        len=strlen(str1);char str2[100];

        for(i=0; i<=(len-1)/2; i++) {
            str2[i]=str1[i*2];}
        str2[(len-1)/2+1]=str1[len-1];
        printf("%s\n",str2);
        t--;
  }
}


#include<stdio.h>
#include<string.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t)
    {
        char str[100];
        int i,n;
        scanf("%s",str);
        n=strlen(str);
        for(i=0;i<n-1;i++)
        {
            if(i%2==0)
                printf("%c",str[i]);
        }
        printf("%c",str[i]);
        t--;
    }
}


#include<stdio.h>
#include<string.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t)
    {
        char str[100];
        int i;
        gets(str);
        n=strlen(str);
        for(i=0;i<n-1;i++)
        {
            if(i%2==0)
                printf("%c",str[i]);
        }
        printf("%c",str[i]);
        t--;
    }
}


#include<stdio.h>
#include<string.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t)
    {
        char str[100];
        int i,n;
        scanf("%s",str);
        n=strlen(str);
        for(i=0;i<n-1;i++)
        {
            if(i%2==0)
                printf("%c",str[i]);
        }
        printf("%c\n",str[i]);
        t--;
    }
}


#include <stdio.h>
#include <string.h>
int main(void)
{
	int n;
	char s[100];
	scanf("%d", &n);
	while(n--)
	{
		scanf("%s", &s);
		for(int i = 0, a = strlen(s); i < a; i++)
		{
			if(i == 0 || i % 2 == 0 || i == a-1)
			printf("%c", s[i]);
		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	char s[1000][100];
	int ch;
	while((ch = getchar()) != '\n' && ch!= EOF);
	for(int i = 0; i < n; i++)
	{
		scanf("%s", &s[i]);
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0, a = strlen(s[i]); j < a; j++)
		{
			if(j % 2 != 0 || j == 0)
			printf("%c", s[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	char s[n][100];
	while(getchar() != '\n');
	for(int i = 0; i < n; i++)
	{
		scanf("%s", &s[i]);
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0, n = strlen(s[i]); j < n; j++)
		{
			if(j % 2 != 0 || j == 0)
			printf("%c", s[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int main(void)
{
	int n;
	scanf("%d", &n);
	char s[1000][100];
	while(getchar() != '\n');
	for(int i = 0; i < n; i++)
	{
		scanf("%s", &s[i]);
	}
	for(int i = 0; i < n; i++)
	{
		for(int j = 0, a = strlen(s[i]); j < a; j++)
		{
			if(j % 2 != 0 || j == 0)
			printf("%c", s[i][j]);
		}
		printf("\n");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
const lli mod = 1e9+7;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
lli p2(lli n){lli ans=0;while(n>=1){n=n/2;ans++;}return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli add(lli a,lli b){return(a+b)%mod;}
lli mul(lli a,lli b){return (a*b)%mod;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
vll setprime(lli n)
{
    vll prime;
    if(n%2==0)
    {
        prime.pb(2);
        while(n%2==0){n/=2;}
    }
    for(lli i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)
        {
            while(n%i==0){n=n/i;}
            prime.pb(i);
        }
    }
    if(n>1)prime.pb(n);
    return prime;
}
///-----------------------TEMP TSF99--------------------------------------------------------------------------------------///
string grid[2000];
int vis[2000][2000];
int n,m;
bool valid(int i,int j)
{
    if(i<0 or i>=n or j<0 or j>=m or vis[i][j]==1 or grid[i][j]=='T')return false;
    return true;
}
int ans,dis=100000;
void dfs(int i,int j,int c=0)
{
    if(valid(i,j)==false )return;
    if(grid[i][j]=='E')
    {
        dis=min(c,dis);
        return;
    }
    vis[i][j]=1;
    dfs(i,j-1,c+1);dfs(i,j+1,c+1);dfs(i+1,j,c+1);dfs(i-1,j,c+1);
}
void dfs1(int i,int j,int c)
{
    if(valid(i,j)==false or c>dis)return;
    vis[i][j]=1;
    if(grid[i][j]!='E' and grid[i][j]!='S')ans+=grid[i][j]-'0';
    dfs1(i,j-1,c+1);dfs1(i,j+1,c+1);dfs1(i+1,j,c+1);dfs1(i-1,j,c+1);

}
void solve()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>grid[i];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='S')
            {
                dfs(i,j);
            }
        }
    }
    memset(vis,0,sizeof vis);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='E')
            {
                dfs1(i,j,0);
            }
        }
    }
    cout<<ans<<endl;

}
int main()
{
    int t=1;//cin>>t;
    while(t--)
    {
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
const lli mod = 1e9+7;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
lli p2(lli n){lli ans=0;while(n>=1){n=n/2;ans++;}return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli add(lli a,lli b){return(a+b)%mod;}
lli mul(lli a,lli b){return (a*b)%mod;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
vll setprime(lli n)
{
    vll prime;
    if(n%2==0)
    {
        prime.pb(2);
        while(n%2==0){n/=2;}
    }
    for(lli i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)
        {
            while(n%i==0){n=n/i;}
            prime.pb(i);
        }
    }
    if(n>1)prime.pb(n);
    return prime;
}
///-----------------------TEMP TSF99--------------------------------------------------------------------------------------///

const int N=1007;
char a[N][N];
int n,m,dis[N][N],sx,sy,tx,ty,ans;
const int x_[4]={1,-1,0,0};
const int y_[4]={0,0,1,-1};
struct node{
	int x,y,d;
};
queue<node>q;
void bfs(int tx,int ty){
	q.push(node{tx,ty,0});
	dis[tx][ty]=-1;
	int x,y;
	while(!q.empty()){
		node now=q.front();q.pop();
		for(int i=0;i<4;i++){
			x=now.x+x_[i];
			y=now.y+y_[i];
			if(x<1||y<1||x>n||y>m||dis[x][y]!=0||a[x][y]=='T')continue;
			q.push(node{x,y,now.d+1});
			dis[x][y]=now.d+1;
		}
	}
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		if(a[i][j]=='S'){sx=i;sy=j;}
		if(a[i][j]=='E'){tx=i;ty=j;}
	}
	bfs(tx,ty);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
		if(dis[i][j]!=0&&dis[i][j]<=dis[sx][sy]&&a[i][j]>='0'&&a[i][j]<='9')ans+=a[i][j]-'0';
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mp  make_pair
#define ss  second
#define ff  first
#define all(x) x.begin(),x.end()
const lli mod = 1e9+7;
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
lli p2(lli n){lli ans=0;while(n>=1){n=n/2;ans++;}return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli add(lli a,lli b){return(a+b)%mod;}
lli mul(lli a,lli b){return (a*b)%mod;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
vll setprime(lli n)
{
    vll prime;
    if(n%2==0)
    {
        prime.pb(2);
        while(n%2==0){n/=2;}
    }
    for(lli i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)
        {
            while(n%i==0){n=n/i;}
            prime.pb(i);
        }
    }
    if(n>1)prime.pb(n);
    return prime;
}
///-----------------------TEMP TSF99--------------------------------------------------------------------------------------///
string grid[2000];
int vis[2000][2000];
int n,m;
bool valid(int i,int j)
{
    if(i<0 or i>=n or j<0 or j>=m or vis[i][j]==1 or grid[i][j]=='T')return false;
    return true;
}
bool f;
int ans,dis;
void dfs(int i,int j,int c=0)
{
    if(valid(i,j)==false or f==true)return;
    if(grid[i][j]=='E')
    {
        f=true;
        dis=c;
        return;
    }
    vis[i][j]=1;
    dfs(i+1,j,c+1);dfs(i-1,j,c+1);dfs(i,j-1,c+1);dfs(i,j+1,c+1);
}
void dfs1(int i,int j,int c)
{
    if(valid(i,j)==false or c>dis)return;
    vis[i][j]=1;
    ans+=grid[i][j]-'0';
    //if(grid[i][j]!='0')cout<<grid[i][j]<<endl;
    dfs1(i+1,j,c+1);dfs1(i-1,j,c+1);dfs1(i,j-1,c+1);dfs1(i,j+1,c+1);

}
void solve()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>grid[i];

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='S')
            {
                dfs(i,j);
            }
        }
    }
   // cout<<dis<<endl;
    memset(vis,0,sizeof vis);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(grid[i][j]=='E')
            {
                dfs1(i,j,0);
            }
        }
    }
    ans-='S'-'0';
    ans-='E'-'0';
    cout<<ans<<endl;

}
int main()
{
    int t=1;//cin>>t;
    while(t--)
    {
        solve();
    }
}


/*
   _____              _____  .____   __      __  _____ _____.___.______________________________
  /  _  \   ______   /  _  \ |    | /  \    /  \/  _  \\__  |   |\____    /\____    /\____    /
 /  /_\  \ /  ___/  /  /_\  \|    | \   \/\/   /  /_\  \/   |   |  /     /   /     /   /     /
/    |    \\___ \  /    |    \    |__\        /    |    \____   | /     /_  /     /_  /     /_
\____|__  /____  > \____|__  /_______ \__/\  /\____|__  / ______|/_______ \/_______ \/_______ \
        \/     \/          \/        \/    \/         \/\/               \/        \/        \/
*/
/*

 ▄▄▄        ██████     ▄▄▄       ██▓     █     █░ ▄▄▄     ▓██   ██▓▒███████▒▒███████▒▒███████▒
▒████▄    ▒██    ▒    ▒████▄    ▓██▒    ▓█░ █ ░█░▒████▄    ▒██  ██▒▒ ▒ ▒ ▄▀░▒ ▒ ▒ ▄▀░▒ ▒ ▒ ▄▀░
▒██  ▀█▄  ░ ▓██▄      ▒██  ▀█▄  ▒██░    ▒█░ █ ░█ ▒██  ▀█▄   ▒██ ██░░ ▒ ▄▀▒░ ░ ▒ ▄▀▒░ ░ ▒ ▄▀▒░
░██▄▄▄▄██   ▒   ██▒   ░██▄▄▄▄██ ▒██░    ░█░ █ ░█ ░██▄▄▄▄██  ░ ▐██▓░  ▄▀▒   ░  ▄▀▒   ░  ▄▀▒   ░
 ▓█   ▓██▒▒██████▒▒    ▓█   ▓██▒░██████▒░░██▒██▓  ▓█   ▓██▒ ░ ██▒▓░▒███████▒▒███████▒▒███████▒
 ▒▒   ▓▒█░▒ ▒▓▒ ▒ ░    ▒▒   ▓▒█░░ ▒░▓  ░░ ▓░▒ ▒   ▒▒   ▓▒█░  ██▒▒▒ ░▒▒ ▓░▒░▒░▒▒ ▓░▒░▒░▒▒ ▓░▒░▒
  ▒   ▒▒ ░░ ░▒  ░ ░     ▒   ▒▒ ░░ ░ ▒  ░  ▒ ░ ░    ▒   ▒▒ ░▓██ ░▒░ ░░▒ ▒ ░ ▒░░▒ ▒ ░ ▒░░▒ ▒ ░ ▒
  ░   ▒   ░  ░  ░       ░   ▒     ░ ░     ░   ░    ░   ▒   ▒ ▒ ░░  ░ ░ ░ ░ ░░ ░ ░ ░ ░░ ░ ░ ░ ░
      ░  ░      ░           ░  ░    ░  ░    ░          ░  ░░ ░       ░ ░      ░ ░      ░ ░
  */                                                         ░ ░     ░        ░        ░

#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353
#define maxx ((ll)1e6+5)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define int long long
const int N=500005;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll modmul(ll x, ll y){return (x*y)%MOD;}
ll modadd(ll x, ll y){return (x+y)%MOD;}
ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
using namespace std;
ll xx[4]={1,0,-1,0};
ll yy[4]={0,1,0,-1};

signed main(){
    int n,m;
    cin>>n>>m;
    queue < pair< int , int > > q;
    char a[n+10][m+10];
    int sx,sy;
    ll dis[n+40][m+40];
    memset(dis,0,sizeof dis);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='E'){
                q.push({i,j});
                a[i][j]='0';
            }
            if(a[i][j]=='S'){
                sx=i;
                sy=j;
                a[i][j]='0';
            }
        }
    }

    while(!q.empty()){

        pair<int ,int > p=q.front();
        int x=p.first;
        int y=p.second;
        q.pop();
        for(int i=0;i<4;i++){
            if(isdigit(a[x+xx[i]][y+yy[i]]) && !dis[x+xx[i]][y+yy[i]] ){
                q.push({xx[i]+x,yy[i]+y});
                 dis[x+xx[i]][y+yy[i]]=dis[x][y]+1;
            }

        }

    }

    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {

            if(dis[i][j]<=dis[sx][sy] && dis[i][j]>0)ans+=a[i][j]-'0';

        }
    }
    cout<<ans<<endl;

}


// SABKA BAP HAI APUN .. (SAMJE NAA) SABKA BAP ,,,,BHAVIK ASHISH PATALIA
#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353
#define maxx ((ll)1e6+5)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define int long long
const int N=500005;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll modmul(ll x, ll y){return (x*y)%MOD;}
ll modadd(ll x, ll y){return (x+y)%MOD;}
ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
using namespace std;
ll xx[4]={1,0,-1,0};
ll yy[4]={0,1,0,-1};

signed main(){
    int n,m;
    cin>>n>>m;
    queue < pair< int , int > > q;
    char a[n+10][m+10];
    int sx,sy;
    ll dis[n+40][m+40];
    memset(dis,0,sizeof dis);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='E'){
                q.push({i,j});
                a[i][j]='0';
            }
            if(a[i][j]=='S'){
                sx=i;
                sy=j;
                a[i][j]='0';
            }
        }
    }

    while(!q.empty()){

        pair<int ,int > p=q.front();
        int x=p.first;
        int y=p.second;
        q.pop();
        for(int i=0;i<4;i++){
            if(isdigit(a[x+xx[i]][y+yy[i]]) && !dis[x+xx[i]][y+yy[i]] ){
                q.push({xx[i]+x,yy[i]+y});
                 dis[x+xx[i]][y+yy[i]]=dis[x][y]+1;
            }

        }

    }

        ll ans=0;
       for(ll j=1;j<=n;j++){for(ll i=1;i<=m;i++){cout<<dis[j][i]<<" ";}cout<<endl;}
       //cout<<sx<<sy<<endl;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {

            if(dis[i][j]<=dis[sx][sy] && dis[i][j]>0)ans+=a[i][j]-'0';

        }
    }
    cout<<ans<<endl;

}


// SABKA BAP HAI APUN .. (SAMJE NAA) SABKA BAP ,,,,BHAVIK ASHISH PATALIA
#include <bits/stdc++.h>
#define ll long long
#define MOD 998244353
#define maxx ((ll)1e6+5)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define int long long
const int N=500005;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[r],MOD-2)))%MOD; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(fpow(fact[n-r],MOD-2)))%MOD; return res;}
ll modmul(ll x, ll y){return (x*y)%MOD;}
ll modadd(ll x, ll y){return (x+y)%MOD;}
ll modsub(ll x, ll y){return (x-y+MOD)%MOD;}
using namespace std;
ll xx[4]={1,0,-1,0};
ll yy[4]={0,1,0,-1};

signed main(){
    int n,m;
    cin>>n>>m;
    queue < pair< int , int > > q;
    char a[n+10][m+10];
    int sx,sy;
    ll dis[n+40][m+40];
    memset(dis,0,sizeof dis);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='E'){
                q.push({i,j});
                a[i][j]='0';
            }
            if(a[i][j]=='S'){
                sx=i;
                sy=j;
                a[i][j]='0';
            }
        }
    }

    while(!q.empty()){

        pair<int ,int > p=q.front();
        int x=p.first;
        int y=p.second;
        q.pop();
        for(int i=0;i<4;i++){
            if(isdigit(a[x+xx[i]][y+yy[i]]) && !dis[x+xx[i]][y+yy[i]] ){
                q.push({xx[i]+x,yy[i]+y});
                 dis[x+xx[i]][y+yy[i]]=dis[x][y]+1;
            }

        }

    }

        ll ans=0;

       //cout<<sx<<sy<<endl;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {

            if(dis[i][j]<=dis[sx][sy] && dis[i][j]>0)ans+=a[i][j]-'0';

        }
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define pii pair<int, int>
#define N 1010
using namespace std;
struct ar
{
    int value, x, y;
};

int a[N][N], d[N][N], v[N][N];;
int row, column;

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

bool check(int r, int c)
{
    return (r >= 0) && (r < row) && (c >= 0) && (c < column);
}

int bfs(int start_x, int start_y, int finish_x, int finish_y)
{
    int i, j;

    for(i=0;i<1001;i++)
    {
        for(j=0;j<1001;j++)
        {
            d[i][j] = v[i][j] = 0;
        }
    }

    v[start_x][start_y] = 1;

    queue<pii>q;
    q.push(pii(start_x, start_y));

    while(!q.empty())
    {
        pii r = q.front();
        q.pop();

        if(r.first == finish_x && r.second == finish_y)
            return d[finish_x][finish_y];

        for(i=0;i<4;i++)
        {
            int tx = r.first + x[i];
            int ty = r.second + y[i];

            if(check(tx, ty) && a[tx][ty] == 1 && v[tx][ty] == 0)
            {
                v[tx][ty] = 1;
                d[tx][ty] = d[r.first][r.second] + 1;
                q.push(pii(tx, ty));
            }
        }
    }

    return -1;
}

int main()
{
    ios_base :: sync_with_stdio(false)
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> row >> column;

    char ch;
    vector<ar>s;
    int sx, sy, fx, fy;

    for(int i=0; i<row; i++)
    {
        for(int j=0; j<column; j++)
        {
            cin >> ch;
            if(ch == '0')
                a[i][j] = 1;
            else if(ch >= '1' && ch <= '9')
            {
                a[i][j] = 1;
                int p = ch - '0';
                s.push_back({p, i, j});
            }
            else if(ch == 'T')
                a[i][j] = 0;
            else if(ch == 'S')
            {
                a[i][j] = 1;
                sx = i;
                sy = j;
            }
            else if(ch == 'E')
            {
                a[i][j] = 1;
                fx = i;
                fy = j;
            }
        }
    }

    int dis = bfs(sx, sy, fx, fy), c = 0;

    for(int i=0; i<s.size(); i++)
    {
        int d1 = s[i].value;
        int sx1 = s[i].x;
        int sy1 = s[i].y;

        int t = bfs(sx1, sy1, fx, fy);
        if(t != -1)
        {
            if(t <= dis)
            {
                c += d1;
            }
        }
    }

    cout << c << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define pii pair<int, int>
#define N 1010
using namespace std;
struct ar
{
    int value, x, y;
};

int a[N][N], d[N][N], v[N][N], dis = 10000000;
int row, column;

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

bool check(int r, int c)
{
    return (r >= 0) && (r < row) && (c >= 0) && (c < column);
}

int bfs(int start_x, int start_y, int finish_x, int finish_y)
{
    int i, j;

    for(i=0;i<1001;i++)
    {
        for(j=0;j<1001;j++)
        {
            d[i][j] = v[i][j] = 0;
        }
    }

    v[start_x][start_y] = 1;

    queue<pii>q;
    q.push(pii(start_x, start_y));

    while(!q.empty())
    {
        pii r = q.front();
        q.pop();

        if(r.first == finish_x && r.second == finish_y)
            return d[finish_x][finish_y];

        for(i=0;i<4;i++)
        {
            int tx = r.first + x[i];
            int ty = r.second + y[i];

            if(check(tx, ty) && a[tx][ty] == 1 && v[tx][ty] == 0)
            {
                v[tx][ty] = 1;
                d[tx][ty] = d[r.first][r.second] + 1;
                if(dis < d[tx][ty])
                    return -1;

                q.push(pii(tx, ty));
            }
        }
    }

    return -1;
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> row >> column;

    char ch;
    vector<ar>s;
    int sx, sy, fx, fy;

    for(int i=0; i<row; i++)
    {
        for(int j=0; j<column; j++)
        {
            cin >> ch;
            if(ch == '0')
                a[i][j] = 1;
            else if(ch >= '1' && ch <= '9')
            {
                a[i][j] = 1;
                int p = ch - '0';
                s.push_back({p, i, j});
            }
            else if(ch == 'T')
                a[i][j] = 0;
            else if(ch == 'S')
            {
                a[i][j] = 1;
                sx = i;
                sy = j;
            }
            else if(ch == 'E')
            {
                a[i][j] = 1;
                fx = i;
                fy = j;
            }
        }
    }

    dis = bfs(sx, sy, fx, fy);
    int c = 0;

    for(int i=0; i<s.size(); i++)
    {
        int d1 = s[i].value;
        int sx1 = s[i].x;
        int sy1 = s[i].y;

        int t = bfs(sx1, sy1, fx, fy);
        if(t != -1)
        {
            if(t <= dis)
            {
                c += d1;
            }
        }
    }

    cout << c << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define pii pair<int, int>
#define N 1010
using namespace std;
struct ar
{
    int value, x, y;
};

int a[N][N], d[N][N], v[N][N];
int row, column;

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

bool check(int r, int c)
{
    return (r >= 0) && (r < row) && (c >= 0) && (c < column);
}

int bfs(int start_x, int start_y, int finish_x, int finish_y)
{
    int i, j;

    v[finish_x][finish_y] = 1;

    queue<pii>q;
    q.push(pii(finish_x, finish_y));

    while(!q.empty())
    {
        pii r = q.front();
        q.pop();

        for(i=0; i<4; i++)
        {
            int tx = r.first + x[i];
            int ty = r.second + y[i];

            if(check(tx, ty) && a[tx][ty] == 1 && v[tx][ty] == 0)
            {
                v[tx][ty] = 1;
                d[tx][ty] = d[r.first][r.second] + 1;
                q.push(pii(tx, ty));
            }
        }
    }
}

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> row >> column;

    char ch;
    vector<ar>s;
    int sx, sy, fx, fy;

    for(int i=0; i<row; i++)
    {
        for(int j=0; j<column; j++)
        {
            cin >> ch;
            if(ch == '0')
                a[i][j] = 1;
            else if(ch >= '1' && ch <= '9')
            {
                a[i][j] = 1;
                int p = ch - '0';
                s.push_back({p, i, j});
            }
            else if(ch == 'T')
                a[i][j] = 0;
            else if(ch == 'S')
            {
                a[i][j] = 1;
                sx = i;
                sy = j;
            }
            else if(ch == 'E')
            {
                a[i][j] = 1;
                fx = i;
                fy = j;
            }
        }
    }

    bfs(sx, sy, fx, fy);

    int dis = d[sx][sy], c = 0;

    for(int i=0;i<s.size();i++)
    {
        int d1 = s[i].value;
        int sx1 = s[i].x;
        int sy1 = s[i].y;
        int p = d[sx1][sy1];

        if(dis >= p && p != 0)
        {
            c += d1;
        }
    }

    cout << c << "\n";
    return 0;
}


#include<bits/stdc++.h>
#define pii pair<int, int>
#define N 1010
using namespace std;
struct ar
{
    int value, x, y;
};

int a[N][N], d[N][N], v[N][N];;
int row, column;

int x[] = {1, -1, 0, 0};
int y[] = {0, 0, 1, -1};

bool check(int r, int c)
{
    return (r >= 0) && (r < row) && (c >= 0) && (c < column);
}

int bfs(int start_x, int start_y, int finish_x, int finish_y)
{
    int i, j;

    for(i=0;i<1001;i++)
    {
        for(j=0;j<1001;j++)
        {
            d[i][j] = v[i][j] = 0;
        }
    }

    v[start_x][start_y] = 1;

    queue<pii>q;
    q.push(pii(start_x, start_y));

    while(!q.empty())
    {
        pii r = q.front();
        q.pop();

        if(r.first == finish_x && r.second == finish_y)
            return d[finish_x][finish_y];

        for(i=0;i<4;i++)
        {
            int tx = r.first + x[i];
            int ty = r.second + y[i];

            if(check(tx, ty) && a[tx][ty] == 1 && v[tx][ty] == 0)
            {
                v[tx][ty] = 1;
                d[tx][ty] = d[r.first][r.second] + 1;
                q.push(pii(tx, ty));
            }
        }
    }

    return -1;
}

int main()
{
    cin >> row >> column;

    char ch;
    vector<ar>s;
    int sx, sy, fx, fy;

    for(int i=0; i<row; i++)
    {
        for(int j=0; j<column; j++)
        {
            cin >> ch;
            if(ch == '0')
                a[i][j] = 1;
            else if(ch >= '1' && ch <= '9')
            {
                a[i][j] = 1;
                int p = ch - '0';
                s.push_back({p, i, j});
            }
            else if(ch == 'T')
                a[i][j] = 0;
            else if(ch == 'S')
            {
                a[i][j] = 1;
                sx = i;
                sy = j;
            }
            else if(ch == 'E')
            {
                a[i][j] = 1;
                fx = i;
                fy = j;
            }
        }
    }

    int dis = bfs(sx, sy, fx, fy), c = 0;

    for(int i=0; i<s.size(); i++)
    {
        int d1 = s[i].value;
        int sx1 = s[i].x;
        int sy1 = s[i].y;

        int t = bfs(sx1, sy1, fx, fy);
        if(t != -1)
        {
            if(t <= dis)
            {
                c += d1;
            }
        }
    }

    cout << c << "\n";
    return 0;
}