import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author يثمم
 */
public class MinMex {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan =new Scanner(System.in);
        int n =scan.nextInt();
        int m = scan.nextInt();
        int mex=0;
        for(int i=0 ;i<m;i++)
        {
            ArrayList<Long> a = new ArrayList<Long>();
            a.add(scan.nextLong());
            a.add(scan.nextLong());
            Collections.sort(a);
            if(a.get(1)==1||a.get(0)==0)
            {
                mex=1;
            }
            if((a.get(0)>2||a.get(1)<=2)&&mex!=1)
            {
                mex=2;
            }
            if(mex!=2&&mex!=1&&a.get(i)<=2)
            {
                mex=3;
            }
        }
        System.out.println(mex);
        Random r =new Random();
        for(int i=0;i<n;i++)
        {
            System.out.println(r.nextInt(m));
        }

    }

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

/**
 *
 * @author يثمم
 */
public class MinMex {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner scan =new Scanner(System.in);
        int n =scan.nextInt();
        int m = scan.nextInt();
        int mex=0;
        for(int i=0 ;i<m;i++)
        {
            ArrayList<Long> a = new ArrayList<Long>();
            a.add(scan.nextLong());
            a.add(scan.nextLong());
            Collections.sort(a);
            if(a.get(0)>2||a.get(1)<=2)
            {
                mex=2;
            }
            if(mex!=2&&a.get(i)<=2)
            {
                mex=3;
            }
        }
        System.out.println(mex);
        for(int i=0;i<n;i++)
        {
            if(mex==2)
            {
                Random r =new Random();
                System.out.println(r.nextInt(2));
            }
            else if(mex==3)
            {
               System.out.println(i);
            }
        }

    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Dima
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int m = in.readInt();
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < m; i++) {
                int l = in.readInt(), r = in.readInt();
                min = Math.min(min, r - l);
            }
            out.printLine(min + 1);
            for (int i = 0; i < n; i++) out.print((i % (min + 1)) + " ");
            out.printLine();
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;
        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }
        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }
        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }
        public void printLine() {
            writer.println();
        }
        public void close() {
            writer.close();
        }
        public void printLine(int i) {
            writer.println(i);
        }
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }
        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.*;
import java.util.*;

public class AA {
	InputStream is;

	int __t__ = 1;
	int __f__ = 0;
	int __FILE_DEBUG_FLAG__ = __f__;
	String __DEBUG_FILE_NAME__ = "src/T";

	FastScanner in;
	PrintWriter out;

	public void solve() {
		int N = in.nextInt(), M = in.nextInt();
		int minRange = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int l = in.nextInt(), r = in.nextInt();
			minRange = Math.min(minRange, r - l + 1);
		}

		out.println(minRange);
		for (int i = 0; i < N; i++) {
			out.print((i % minRange) + " ");
		}
		out.println();
		out.close();
	}

	public void run() {
		if (__FILE_DEBUG_FLAG__ == __t__) {
			try {
				is = new FileInputStream(__DEBUG_FILE_NAME__);
			} catch (FileNotFoundException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
			System.out.println("FILE_INPUT!");
		} else {
			is = System.in;
		}
		in = new FastScanner(is);
		out = new PrintWriter(System.out);

		solve();
	}

	public static void main(String[] args) {
		new AA().run();
	}

	public void mapDebug(int[][] a) {
		System.out.println("--------map display---------");

		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i].length; j++) {
				System.out.printf("%3d ", a[i][j]);
			}
			System.out.println();
		}

		System.out.println("----------------------------");
		System.out.println();
	}

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] nextIntArray(int n) {
			return nextIntArray(n, 0);
		}

		int[] nextIntArray(int n, int margin) {
			int[] array = new int[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextInt();

			return array;
		}

		int[][] nextIntMap(int n, int m) {
			int[][] map = new int[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextIntArray(m);
			}
			return map;
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		long[] nextLongArray(int n) {
			return nextLongArray(n, 0);
		}

		long[] nextLongArray(int n, int margin) {
			long[] array = new long[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextLong();

			return array;
		}

		long[][] nextLongMap(int n, int m) {
			long[][] map = new long[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextLongArray(m);
			}
			return map;
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		double[] nextDoubleArray(int n) {
			return nextDoubleArray(n, 0);
		}

		double[] nextDoubleArray(int n, int margin) {
			double[] array = new double[n + margin];
			for (int i = 0; i < n; i++)
				array[i + margin] = nextDouble();

			return array;
		}

		double[][] nextDoubleMap(int n, int m) {
			double[][] map = new double[n][m];
			for (int i = 0; i < n; i++) {
				map[i] = in.nextDoubleArray(m);
			}
			return map;
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++)
				array[i] = next();

			return array;
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}


// CodeForces Round #669 C competition

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class AlyonaMex {

	int n,m;
	int []l;
	int []r;
	int []a;
	int maxMex;

	private void readData(BufferedReader bin) throws IOException {
		String s = bin.readLine();
		String []ss = s.split(" ");
		n = Integer.parseInt(ss[0]);
		m = Integer.parseInt(ss[1]);
		a = new int[n];
		r = new int[m];
		l = new int[m];
		for (int i = 0; i < m; i++) {
			s = bin.readLine();
			ss = s.split(" ");
			l[i] = Integer.parseInt(ss[0]);
			r[i] = Integer.parseInt(ss[1]);
		}
	}

	void printRes() {
		System.out.println(maxMex);
		for (int i = 0; i < n; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}

	private void calculate() {
		int minLen = n;
		for (int i=0; i<m; i++) {
			int ln = r[i]-l[i]+1;
			if (ln < minLen) {
				minLen = ln;
			}
		}
		maxMex = minLen;
		int o = 0;
		for (int i=0; i<n; i++) {
			a[i] = o;
			o = (o+1) % maxMex;
		}
	}

	public static void main(String[] args) throws IOException {
		// BufferedReader bin = new BufferedReader(new FileReader("cactus.in"));
		BufferedReader bin = new BufferedReader(
				new InputStreamReader(System.in));
		AlyonaMex l = new AlyonaMex();
		l.readData(bin);
		l.calculate();
		l.printRes();
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int m = in.nextInt();

            int best = Integer.MAX_VALUE;
            int[] s = new int[m];
            int[] e = new int[m];
            for (int i = 0; i < m; i++)
            {
                s[i] = in.nextInt();
                e[i] = in.nextInt();
                best = Math.min(best, e[i] - s[i] + 1);
            }
            out.println(best);
            for (int i = 0; i < n; i++)
            {
                out.print(i % best);
                out.print(" ");
            }
        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author zodiacLeo
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            int n = in.nextInt();
            int m = in.nextInt();

            int best = Integer.MAX_VALUE;
            int[] s = new int[m];
            int[] e = new int[m];
            int[] r = new int[n + 1];
            Arrays.fill(r, Integer.MAX_VALUE);
            for (int i = 0; i < m; i++)
            {
                s[i] = in.nextInt();
                e[i] = in.nextInt();
                r[s[i]] = 0;
                r[e[i]] = Math.min(r[e[i]], e[i] - s[i]);
                best = Math.min(best, e[i] - s[i]);
            }
            out.println(best + 1);
            for (int i = 1; i <= n; i++)
            {
                if (r[i] == Integer.MAX_VALUE)
                {
                    if (r[i - 1] != Integer.MAX_VALUE)
                    {
                        r[i] = r[i - 1] + 1;
                    }
                }
                out.print(r[i] + " ");
            }

        }

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

        public String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                String s = null;
                try
                {
                    s = br.readLine();
                } catch (IOException e)
                {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 5e3 + 7;
const int INF = 1e9 + 7;
int n, m, s[N], sum[N], dp[N], pd[N];
double x[N];
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 1, n + 1)
		scanf("%d %lf", &s[i], &x[i]);
	rep(i, 0, N)
		dp[i] = INF;
	dp[0] = 0;
	rep(i, 1, m + 2) {
		rep(j, 0, n + 1)
			pd[j] = dp[j], dp[j] = INF;
		rep(j, 1, n + 1)
			sum[j] = sum[j - 1] + (s[j] != i);
		int mn = INF;
		rep(j, 0, n + 1) {
			mn = min(mn, pd[j] - sum[j]);
			dp[j] = min(dp[j], mn + sum[j] + (n - j) - (sum[n] - sum[j]));
		}
	}
	int ans = INF;
	rep(i, 0, n + 1)
		ans = min(ans, dp[i]);
	printf("%d", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 5e3 + 7;
const int INF = 1e9 + 7;
int n, m, s[N], g[N], sum[N], dp[N], pd[N];
double x[N];
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 1, n + 1) {
		scanf("%d %lf", &s[i], &x[i]);
		++g[s[i]];
	}
	rep(i, 0, N)
		dp[i] = INF;
	dp[0] = 0;
	rep(i, 1, m + 1) {
		rep(j, 0, n + 1)
			pd[j] = dp[j], dp[j] = INF;
		dp[0] = pd[0] + g[i];
		rep(j, 1, n + 1)
			sum[j] = sum[j - 1] + (s[j] != i);
		int mn = pd[0] - sum[0];
		rep(j, 1, n + 1) {
			mn = min(mn, pd[j] - sum[j]);
			dp[j] = min(dp[j], mn + (n - j) - (sum[n] - sum[j]) + sum[j]);
		}
	}
	int ans = INF;
	rep(i, 0, n + 1)
		ans = min(ans, dp[i]);
	printf("%d", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
//-------head-------
const int N = 5e3 + 7;
const int INF = 1e9 + 7;
int n, m, s[N], sum[N], dp[N], pd[N];
double x[N];
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 1, n + 1)
		scanf("%d %lf", &s[i], &x[i]);
	rep(i, 0, N)
		dp[i] = INF;
	dp[0] = 0;
	rep(i, 1, m + 1) {
		rep(j, 0, n + 1)
			pd[j] = dp[j], dp[j] = INF;
		rep(j, 1, n + 1)
			sum[j] = sum[j - 1] + (s[j] != i);
		int mn = INF;
		rep(j, 0, n + 1) {
			mn = min(mn, pd[j] - sum[j]);
			dp[j] = min(dp[j], mn + sum[j]);
		}
//		rep(j, 0, n + 1)
//			printf("dp[%d][%d] = %d\n", i, j, dp[j]);
	}
	int ans = n;
	rep(i, 0, n + 1)
		ans = min(ans, dp[i] + (n - i));
	printf("%d", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)    ( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-8;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n, m;
int t[N];
int dp[5005][5005];

int solve(int i,int last) {
	if (i == n) return 0;
	int &ret = dp[i][last];
	if (ret != -1) return ret;
	ret = oo;
	if (t[i] >= last) ret = min(ret, solve(i + 1, t[i]));
	ret = min(ret, 1 + solve(i + 1, last));
	return ret;
}

int main() {
	scanf("%d%d",&n,&m);
	loop(i, 0, n - 1) {
		double x;
		scanf("%d%lf", &t[i], &x);
	}
	memset(dp, -1, sizeof dp);
	int ans = solve(0, 0);
	printf("%d",ans);
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	int a[n+1];
	int dp[n+1];
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		double x;
		cin>>x;
	}
	dp[1]=1;
	for(int i=2;i<=n;i++)
	{
		int r=0;
		for (int j=1;j<i;j++)
			if(a[i]>=a[j])
			r=max(r,dp[j]);
        dp[i]=r+1;
	}
	int t=dp[1];
	for (int i=1;i<=n;i++)
		t=max(t,dp[i]);
	cout<<n-t;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asort(s)        sort(s.begin(), s.end())
#define dsort(s)        sort(s.rbegin(), s.rend())
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)

const ll INF = LLONG_MAX;
const ll SZ = 5000+5;
const ll mod = 1e9+7;

ll dp[SZ][SZ];
ll n, m, a[SZ];

ll solve(ll in, ll mx) {
    if(in == n+1) return 0;
    if(dp[in][mx] != -1) return dp[in][mx];

    ll t, res(INF);
    if(a[in] >= mx) {
        t = solve(in+1, a[in]);
        res = min(res, t);

        t = 1 + solve(in+1, mx);
        res = min(res, t);
    }
    else res = 1 + solve(in+1, mx);

    return dp[in][mx] = res;
}

int main() {
    FR;
    ll t = 0, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    cin >> n >> m;

    double xx;

    for1(i, n) cin >> a[i] >> xx;

    ms(dp, -1);

    cout << solve(1, 0) << "\n";

    return 0;
}


#include <cstdio>
#include <vector>
#include <cstdlib>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
	int plantsCount, speciesCount;
	scanf("%d %d", &plantsCount, &speciesCount);

	vector<int> plants;
	for (int i = 0; i < plantsCount; ++i) {
		int plant;
		double tmp;
		scanf("%d %lf", &plant, &tmp);
		plants.push_back(plant - 1);
	}

	vector<vector<int>> dp(plantsCount+1);
	for (int i = 0; i < plantsCount + 1; ++i) {
		dp[i].resize(speciesCount);
	}

	for (int i = 1; i < plantsCount + 1; ++i) {
		for (int j = 0; j < speciesCount; ++j) {
			if (plants[i - 1] == j) {
				for (int k = 0; k <= j; ++k) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k]);
				}

				dp[i][j]++;
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	int maxLength = 0;
	for (int i = 0; i < speciesCount; ++i) {
		maxLength = max(maxLength, dp[plantsCount][i]);
	}

	printf("%d", plantsCount - maxLength);
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>
#include<array>
#include<stdio.h>
#include<cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
ll LLINF = 1e15;
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

//int col[] = {0,-1,0,1,1,1,-1,-1};
int row[] = {-1,0,1,0,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};

vi temp(5000+5);

int n, m, k, x, len;
vi plant(5000+5);

int bs(int x)
{
    int l = 0, r = len, ans;
    while(l <= r)
    {
        int mid = (l+r)/2 ;
        if(plant[temp[mid]] > x)
        {
            r = mid-1;
            ans = mid;
        }
        else
            l = mid+1;
    }

    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);

    double num;
    cin >> n >> m;

    for(int i = 0 ; i < n ; ++i)
        cin >> plant[i] >> num ;

    temp[1] = 0;
    len = 1;

    for(int i = 1 ; i < n ; ++i)
    {
        if(plant[i] >= plant[temp[len]])
        {
            len++;
            temp[len] = i;
        }

        else
            if(plant[i] < plant[temp[1]])
        {
            temp[1] = i;
        }

        else
        {
            int ind = bs(plant[i]);

            temp[ind] = i;
        }
    }
    cout << n-len ;

    return 0;
}


#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>
#include<array>
#include<stdio.h>
#include<cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
ll LLINF = 1e15;
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

//int col[] = {0,-1,0,1,1,1,-1,-1};
int row[] = {-1,0,1,0,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};

vi temp(5000+5,-1);

int n, m, k, x, len;
vi plant(5000+5);

int bs(int x)
{
    int l = 1, r = len, ans;
    while(l <= r)
    {
        int mid = (l+r)/2 ;
        if(plant[temp[mid]] > x)
        {
            r = mid-1;
            ans = mid;
        }
        else
            l = mid+1;
    }

    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);

    double num;
    cin >> n >> m;

    for(int i = 0 ; i < n ; ++i)
        cin >> plant[i] >> num ;

    temp[1] = 0;
    len = 1;

    for(int i = 1 ; i < n ; ++i)
    {
        if(plant[i] >= plant[temp[len]])
        {
            len++;
            temp[len] = i;
        }

        else
            if(plant[i] < plant[temp[1]])
        {
            temp[1] = i;
        }

        else
        {
            int ind = bs(plant[i]);

            temp[ind] = i;
        }
    }

    cout << n-len ;

    return 0;
}


typedef long long ll;
typedef unsigned long long ull;
/*
id: sadykhzadeh -> @Azer_Sadykhzadeh
Programming Language: (C++)
*/
#define qq2(x,y) cout << (#x) << " = " << (x) << '\t' << (#y) << " = " << (y) << endl
#define qq(x) cout << (#x) << " = " << (x) << endl
#define elif else if
#define pb push_back
#define ins insert
#define pow2(x) ((x)*(x))
#define mod(x, m) ((x) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define rus_lang setlocale(LC_ALL , "Russian")
#define F_READ ios_base::sync_with_stdio(false);cin.tie(0)
#define MOD 1000000007LL
#define line cout << endl << endl << "========================" << endl
#define COUT(x) return cout << (x) << endl, 0;
#define stop return 0
using namespace std;
#include <bits/stdc++.h>
ll T1 = clock();
void timer(){rus_lang; ll T2(clock());cerr<<"Time: "<<(T2-T1)/1000.<<" sec."<<endl;
cerr << "Azer_Sadykhzadeh (:";}
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

ll n, m;
vector <pair <ll, long double> > a;
ll cnt = 0;

int f(pair <ll, long double> a, pair <ll, long double> b){
    if(a.first == b.first){
        cnt++;
        return a.second < b.second;
    }
    else{
        cnt++;
    return a.first < b.first;
    }
}

int main(){
    F_READ;
    cout << fixed << setprecision(6);
    cin >> n >> m;
    for(ll i = 0; i < n; i++){
        ll q; long double w;
        cin >> q >> w;
        a.pb({q,w});
    }
    sort(a.begin(), a.end(), f);
    cout << cnt << endl;
    timer(); stop;
}


typedef long long ll;
typedef unsigned long long ull;
/*
id: sadykhzadeh -> @Azer_Sadykhzadeh
Programming Language: (C++)
*/
#define qq2(x,y) cout << (#x) << " = " << (x) << '\t' << (#y) << " = " << (y) << endl
#define qq(x) cout << (#x) << " = " << (x) << endl
#define elif else if
#define pb push_back
#define ins insert
#define pow2(x) ((x)*(x))
#define mod(x, m) ((x) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define rus_lang setlocale(LC_ALL , "Russian")
#define F_READ ios_base::sync_with_stdio(false);cin.tie(0)
#define MOD 1000000007LL
#define line cout << endl << endl << "========================" << endl
#define COUT(x) return cout << (x) << endl, 0;
#define stop return 0
using namespace std;
#include <bits/stdc++.h>
ll T1 = clock();
void timer(){rus_lang; ll T2(clock());cerr<<"Time: "<<(T2-T1)/1000.<<" sec."<<endl;
cerr << "Azer_Sadykhzadeh (:";}
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

ll n, m;
ll a[4005], dp[5004];

int main(){
    F_READ;
    cin >> n >> m;
    for(ll i = 1; i <= n; i++){
        double temp;
        cin >> a[i] >> temp;
    }
    ll ans(0);
    for(ll i = 1; i <= n; i++){
        dp[i] = 1;
        for(ll j = i - 1; j >= 1; j--){
            if(a[i]>=a[j]){
                dp[i] = max(dp[i],dp[j] + 1);
            }
        }
        ans = max(ans, dp[i]);
    }
    cout << n - ans << endl;
    timer();
    stop;
}


typedef long long ll;
typedef unsigned long long ull;
/*
id: sadykhzadeh -> @Azer_Sadykhzadeh
Programming Language: (C++)
*/
#define qq2(x,y) cout << (#x) << " = " << (x) << '\t' << (#y) << " = " << (y) << endl
#define qq(x) cout << (#x) << " = " << (x) << endl
#define elif else if
#define pb push_back
#define ins insert
#define pow2(x) ((x)*(x))
#define mod(x, m) ((x) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define rus_lang setlocale(LC_ALL , "Russian")
#define F_READ ios_base::sync_with_stdio(false);cin.tie(0)
#define MOD 1000000007LL
#define line cout << endl << endl << "========================" << endl
#define COUT(x) return cout << (x) << endl, 0;
#define stop return 0
using namespace std;
#include <bits/stdc++.h>
ll T1 = clock();
void timer(){rus_lang; ll T2(clock());cerr<<"Time: "<<(T2-T1)/1000.<<" sec."<<endl;
cerr << "Azer_Sadykhzadeh (:";}
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

ll n, m;
ll a[5005], dp[5004];

int main(){
    F_READ;
    cin >> n >> m;
    for(ll i = 1; i <= n; i++){
        double temp;
        cin >> a[i] >> temp;
    }
    ll ans(0);
    for(ll i = 1; i <= n; i++){
        dp[i] = 1;
        for(ll j = i - 1; j >= 1; j--){
            if(a[i] >= a[j]){
                dp[i] = max(dp[i],dp[j] + 1);
            }
        }
        ans = max(ans, dp[i]);
    }
    cout << n - ans << endl;
    timer();
    stop;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[5005],dp[5005];
int main()
{
    int n,m,ans=0,i,j;
    cin>>n>>m;
    long double x;
    for(i=1;i<=n;i++)
        cin>>a[i]>>x;

    for(i=1;i<=n;i++)
    {
        dp[i]=1;
        for(j=1;j<i;j++)
        {
            if(a[j]<=a[i])
                dp[i]=max(dp[i],dp[j]+1);
        }
        //cout<<dp[i]<<endl;
        ans=max(ans,dp[i]);
    }
    cout<<n-ans;
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int a[5005],dp[5005];
int main()
{
    int n,m,x,ans=0,i,j;
    cin>>n>>m;

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

    for(i=1;i<=n;i++)
    {
        dp[i]=1;
        for(j=1;j<i;j++)
        {
            if(a[j]<=a[i])
                dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,dp[i]);
    }
    cout<<n-ans;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
}
int mem[5009][5009], s[5009], n, m;
double p[5007];
int solve(int idx, int pre)
{
	if (idx == n)return 0;
	int& ret = mem[idx][pre];
	if (~ret)return ret;
	ret = solve(idx + 1, pre);
	if (s[idx] >= s[pre])
		ret = max(ret, solve(idx + 1, idx) + 1);
	return ret;
}
int main()
{
	GOAT();
	memset(mem, -1, sizeof mem);
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> s[i] >> p[i];
	int ans = 0;
	for (int i = 0; i < n; i++)
    ans = max(ans, solve(i, i));
	cout <<n-ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define bay_bay return 0;
#define fori(n) for(int i=0;i<n;++i)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) v.size()
#define endl "\n"
constexpr auto EPS = 1e-9;
#define ff fflush(stdout);
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
}
int mem[5009][5009], s[5009], n, m;
double p[5007];
int solve(int idx, int pre)
{
	if (idx == n)return 0;
	int& ret = mem[idx][pre];
	if (~ret)return ret;
	ret = solve(idx + 1, pre);
	if (s[idx] >= s[pre])
		ret = max(ret, solve(idx + 1, idx) + 1);
	return ret;
}
int main()
{
	GOAT();
	memset(mem, -1, sizeof mem);
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> s[i] >> p[i];
	cout <<n-solve(0, n) << endl;

}


/************************
    LIS (nlogn): elements are range from -MX to MX
***********************/

#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <memory.h>
#include <algorithm>
#define case        printf("Case %d: ",++tc);
#define read        freopen("tst.txt","r",stdin)
#define write       freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define pi acos(-1)
#define mx 5002
#define MX INT_MAX
int ar[mx],dp[mx];

int n;
int fn(int x){
    int id = upper_bound(dp,dp+n,x)-dp;
    return id;
}

main(){
int t,tc = 0;
scanf("%d%d",&n,&t);
double x;
for(int i = 0; i<n; i++)    scanf("%d%lf",ar+i,&x);

fill(dp,dp+mx,MX);

int ans = 0;
dp[0] = -MX;
for(int i = 0; i<n; i++){
    int x = ar[i];
    int id = fn(x);
    dp[id] = min(dp[id],x);
    ans = max(ans,id);
}
printf("%d\n",n-ans);

return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <memory.h>
#include <algorithm>
#define case        printf("Case %d: ",++tc);
#define read        freopen("tst.txt","r",stdin)
#define write       freopen("out.txt","w",stdout)
typedef long long ll;
using namespace std;
#define pi acos(-1)
#define mx 5005
int ar[mx],dp[mx];

main(){
int t,tc = 0;

int n;
cin>>n>>t;
double x;
for(int i = 0; i<n; i++)    cin>>ar[i]>>x;
int ans = 0;
for(int i = 0; i<n; i++){
    dp[i] = 1;
    for(int j = 0; j<i; j++){
        if(ar[i]>=ar[j]) dp[i] = max(dp[i],dp[j]+1);
    }
    ans = max(ans,dp[i]);
}

cout<<n-ans<<endl;

return 0;
}


// Lets go to the next level
// AIM CM at CF *__* asap
// Hit A,B,C and D faster and reach Candidate Master
// template taken from Striver_79
// Remember you were also a novice when you started,
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.
// Any doubts or want to have a talk, contact https://www.facebook.com/raj.striver

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int) 1000000007
#define MOD (int) 1e9+7
// Big two primes
#define X 1001100011100001111ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define kitna se
#define endl "\n"
#define pi pair<int, int>
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}
void pr(int x){cout << x;}
void prl(int x){cout << x << endl;}
//bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;}
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N =  (int)(5*1e3 + 5);

//vector<int>vec[nax];

// int spf[N+5];

// void SOF()
// {
//     spf[1] = 1;
//     for (int i=2; i<N; i++)

//         // marking smallest prime factor for every
//         // number to be itself.
//         spf[i] = i;

//     // separately marking spf for every even
//     // number as 2
//     for (int i=4; i<N; i+=2)
//         spf[i] = 2;

//     for (int i=3; i*i<N; i++)
//     {
//         // checking if i is prime
//         if (spf[i] == i)
//         {
//             // marking SPF for all numbers divisitedible by i
//             for (int j=i*i; j<N; j+=i)

//                 // marking spf[j] if it is not
//                 // previously marked
//                 if (spf[j]==j)
//                     spf[j] = i;
//         }
//     }
// }

// int C[10005][10005];
// int binomialCoeff(int n, int k)
// {
//     // int C[n + 1][k + 1];
//     int i, j;

//     // Caculate value of Binomial Coefficient
//     // in bottom up manner
//     for (i = 0; i <= n; i++)
//     {
//         for (j = 0; j <= min(i, k); j++)
//         {
//             // Base Cases
//             if (j == 0 || j == i)
//                 C[i][j] = 1;

//             // Calculate value using previosly
//             // stored values
//             else
//                 C[i][j] = C[i - 1][j - 1] +
//                           C[i - 1][j];
//         }
//     }

//     return C[n][k];
// }
bool isPowerOfTwo(int x)
{
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x&(x-1)));
}
int a[N];
int n, m;
int dp[N][N];
int longest(int ind, int last)
{
  if(ind>n) return 0;
  if(dp[ind][last]!=-1) return dp[ind][last];
  int ans = 0;
  for(int i = ind;i<=n;i++)
  {
    if(a[i]>=a[last])
    ans = max(ans, 1 + longest(i+1, i));
  }

  return dp[ind][last] = ans;
}

signed main(){
  #ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
  #endif

//SOF();
fio;
//spf[1] = 0;

//srand(time(NULL));
int t = 1;
//cin >> t;

while(t--){
  cin >> n >> m;
  double x;
  for1(i,n)
  {
    cin >> a[i] >> x;
  }
  ini(dp,-1);
  cout << n - longest(1,0);

}
}


#include <bits/stdc++.h>
using namespace std;
long long ll,i,j,k,l,m,s,t,n,x,y,cl,ss,ce,a[623456],b[212345],c[212356],d[1234];
vector <string> p,r,q;
int main() {
//    freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    cin >> n;
    for (i = 0; i <n; i ++){
        cin >> a[i]>>x;
    }
    b[0] = 1;
    for (i = 1; i < n; i ++){
        b[i] = 1;
        for (j = 0; j < i; j ++){
            if (a[i]>a[j])
                b[i] = max(b[i],b[j]+1);
        }
    }
    for (i = 0 ; i < n; i ++)
        s = max (s,b[i]);

    cout << n-s;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long ll,i,j,k,l,m,s,t,n,x,y,cl,ss,ce,a[623456],b[212345],c[212356],d[1234];
vector <string> p,r,q;
int main() {
//    freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    cin >> n;
    for (i = 0; i <n; i ++){
        cin >> a[i]>>x;
    }
    b[0] = 1;
    for (i = 1; i < n; i ++){
        b[i] = 1;
        for (j = 0; j < i; j ++){
            if (a[i]>=a[j])
                b[i] = max(b[i],b[j]+1);
        }
    }
    for (i = 0 ; i < n; i ++)
        s = max (s,b[i]);

    cout << n-s;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long ll,i,j,k,l,m,s,t,n,y,cl,ss,ce,a[623456],b[212345],c[212356],d[1234];
double x;
vector <string> p,r,q;
int main() {
//    freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
    cin >> n>>m;
    for (i = 0; i <n; i ++){
        cin >> a[i]>>x;
        //cout << a[i]<<' ';
    }
    b[0] = 1;
    for (i = 1; i < n; i ++){
        b[i] = 1;
        for (j = 0; j < i; j ++){
            if (a[i]>=a[j])
                b[i] = max(b[i],b[j]+1);
        }
       // cout << b[i] <<endl;
    }
    for (i = 0 ; i < n; i ++)
        s = max (s,b[i]);
   // cout << s<<endl;

    cout << n-s;
    return 0;
}


#include <bits/stdc++.h>
using namespace std ;

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    int n, m, x, ans=-1, idx ;
    double pos ;
    cin>> n >> m ;
    vector<pair<double, int>> plants ;
    vi dp(n), seq ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> x >> pos ;
        plants.pb(mp(pos, x)) ;
      }
    sort(all(plants)) ;
    seq.pb(plants[0].se) ;
    ans=1 ;
    dp[0]=1 ;
    for(int i=1 ; i<n ; i++)
      {
        x=plants[i].se ;
        idx=upper_bound(seq.begin(), seq.end(), x)-seq.begin() ;
        if(idx==seq.size()) seq.pb(x) ;
        else seq[idx]=x ;
        dp[i]=idx+1 ;
      }
    cout<< n-*max_element(all(dp)) ;
  }


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vll vector<ll>
#define pb push_back
#define sf scanf
#define ff first
#define M 1000000007
#define ss second
#define pf printf
#define mp make_pair
#define all(V) V.begin(),V.end()

using namespace std;

int lis(vll A,int n)
{

        vll tail(n);
        tail[0]=A[0];
        int len=1;
        for(int i=1;i<A.size();i++)
        {
                if(A[i]<tail[0])//If the element is the least, replaces the first element of all lists
                {
                        tail[0]=A[i];
                }
                if(A[i]>tail[len-1]) //If the element is greater than all other, then appends to all the list
                {
                        tail[len++]=A[i];
                }
                else
                {
                        *lower_bound(tail.begin(),tail.begin()+len,A[i])=A[i]; //Finds the lower bound of the index and replaces it with A[i]
                }
        }
        return len;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,m;
	cin>>n>>m;
	vll a(n);
	float t;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>t;
		a[i]*=10000;
		a[i]+=2;
	}
	for(int i=0,j=1;i<n;i++,j++)
	{
		a[i]+=j;
		//cout<<a[i]<<" ";
	}
	//cout<<endl;
	cout<<n-lis(a,n)<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define fastio                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

using namespace std;

int main() {

    int n, m;
    cin >> n >> m;

    vector<int> x(n);
    vector<double> s(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> s[i];
    }

    vector<int> dp(n, 1);

    for(int i = 1; i < n; i++) {
        for(int j = 0; j < i; j++) {
            if(x[j] <= x[i]) {
                dp[i] = max(dp[i], dp[j]+1);
            }
        }
    }
    int res = INT_MIN;
    for(int i = 0; i < n; i++) {
        res = max(res, dp[i]);
    }
    cout << n - res;

}


#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 5010

int type[MAX],dp[MAX];

int main()
{
	int n,m;
	cin>>n>>m;

	int x;
	float y;
	for(int i=1;i<=n;i++)
	{
		cin>>type[i];
		cin>>y;
	}

	for(int i=1;i<=n;i++)
	{
		int j=type[i];
		for(int k=j;k>=1;k--)
			dp[j]=max(dp[j],dp[k]+1);
	}

	int ans=0;
	for(int i=0;i<=n;i++)
		ans=max(ans,dp[i]);

	cout<<n-ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
int n, k, arr[5005], dp[5005][5005];
double x;
int solve(int i, int j)
{
    if(i == n)      return 0;
    if(~dp[i][j])   return dp[i][j];
    int ans = solve(i + 1, j) + (arr[i] != j);
    if(j < k)           ans = min(ans, solve(i, j + 1));
    return dp[i][j] = ans;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    memset(dp, -1, sizeof dp);
    for(int i = 0;i < n;++i)
        cin >> arr[i] >> x;
    cout << solve(0, 1);
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n';
using namespace std;
typedef long long int LL;

const int N=5005;
int dp[N],a[N];

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

  //freopen("input.in","r",stdin);

   int n,m,res=0;
   cin>>n>>m;

   float x;

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

   for(int i=1;i<=n;i++)
   {
   	 for(int j=i-1;j>=1;j--)
   	 	if(a[j]<=a[i])dp[i]=max(dp[i],dp[j]);
   	 dp[i]++;res=max(res,dp[i]);
   }
   cout<<n-res<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define f first
#define s second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;

const int inf = (int)1e9;
const ll llinf = (ll)9e18;
const int N = (int)1e6 + 111;

int main()
{
	ld x;
	int n, m, ans = 0;
	scanf("%d %d", &n, &m);
	vi a(n);
	for (int i = 0; i < n; i++)
		scanf("%d %Lf", &a[i], &x);
	vi d(n + 1, inf);
	d[0] = -inf;
	for (int i = 0; i < n; i++)
	{
		int j = (upper_bound(d.begin(), d.end(), a[i]) - d.begin());
		d[j] = a[i];
		ans = max(ans, j);
	}
	printf("%d", n - ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define fr first
#define sc second
#define null NULL
#define mp make_pair
#define pb push_back
#define LN(A) strlen(A)
#define PQ priority_queue
#define SZ(A) int(A.size())
#define All(A) A.begin(), A.end()
#define rAll(A) A.rbegin(), A.rend()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
const double EPS = 1e-9, PI = acos(-1);
const int mod = int(1e9) + 7;

const int MX = 5010;
int memo[MX][MX], A[MX], n, m;

int dp(int i = 0, int j = 0) {
  if(i == n) return 0;
  int& ret = memo[i][j];
  if(ret + 1) return ret;
  ret = dp(i + 1, j);
  if(j <= A[i])
    ret = max(ret, 1 + dp(i + 1, A[i]));
  return ret;
}

void solve() {
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; ++i) {
    double x;
    scanf("%d %lf", &A[i], &x);
  }
  memset(memo, -1, sizeof memo);
  printf("%d\n", n - dp());
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#else
#endif
  solve();
}


#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
int n,m,pos[maxn],dp[maxn],ans=0;
double d;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n>>m;
    rep(i,1,n+1){
        int x,tmp=0;cin>>x>>d;
        rep(j,0,x+1) tmp=max(dp[j],tmp);
        dp[x]=max(dp[x],tmp+1);
        ans=max(ans,dp[x]);
    }
    cout<<n-ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
int n,m,a[maxn],pos[maxn],cnt[maxn],vis[maxn];
double d;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n>>m;
    rep(i,1,n+1){
        cin>>a[i]>>d;
        pos[a[i]]=i,cnt[a[i]]++;
    }
    int ans=0;
    rep(i,1,m+1){
        int flag=0,tmp=0,val=maxn;
        rep(j,1,pos[i]+1){
            if(vis[j]==-1) continue;
            if(a[j]!=i) flag++;
            else{
                if(flag)   tmp++;
                else cnt[i]--;
                vis[j]=-1;
            }
            val=min(val,cnt[i]-tmp+min(tmp,flag));
        }
        ans+=val;
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=5e3+10;
const int maxm=5e5+10;
const ll INF=1e18;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
int n,m,a[maxn],pos[maxn],cnt[maxn],vis[maxn];
double d;
int main(){
    ios::sync_with_stdio(false);/*
    freopen("d://in.txt","r",stdin);
    freopen("d://out.txt","w",stdout);*/
    cin>>n>>m;
    rep(i,1,n+1){
        cin>>a[i]>>d;
        pos[a[i]]=i;
    }
    int ans=0;
    rep(i,1,m+1){
        int flag=0,tmp=0;
        rep(j,1,pos[i]+1){
            if(vis[j]!=-1&&a[j]!=i) flag++;
            if(flag&&a[j]==i) tmp++;
            if(a[j]==i) vis[j]=-1;
        }
        ans+=min(flag,tmp);
    }
    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define LL long long

using namespace std;

const int B = 317;
const int N = 1e9 + 7;
const int maxn = 1e6 + 7;
const LL mod = 998244353;
const LL inf = 1e18;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int n,m;
    cin >> n >> m;
    vector < int > a(n);
    vector < int > d(m + 1);
    for( int i = 0; i < n; i++ ){
        cin >> a[i];
        double x;
        cin >> x;
    }
    for( int i = 0; i < n; i++ ){
        for( int j = a[i]; j >= 1; j-- ){
            d[a[i]] = max( d[a[i]] , d[j] + 1 );
        }
    }
    cout << n - *max_element(d.begin() , d.end());
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("arrayop.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    n *= 3;
    int a[n];
    fill(a, a + n, -1);
    rep(i, 0, n / 3)
    {
        cin >> a[n / 3 + i];
        a[n / 3 + i]--;
        double x;
        cin >> x;
    }
    int p = 0;
    int dp[2][n];
    int pref[2][n];
    int cnt[2][n];
    rep(i, 0, n)
        dp[p][i] = 0;
    rep(i, 0, n)
        if (a[i] == 0)
            cnt[p ^ 1][i] = 1;
        else
            cnt[p ^ 1][i] = 0;
    rep(i, 1, n)
        cnt[p ^ 1][i] += cnt[p ^ 1][i - 1];
    rep(i, 0, n)
        pref[p][i] = dp[p][i] + cnt[p ^ 1][i];
    rep(i, 1, n)
        pref[p][i] = min(pref[p][i], pref[p][i - 1]);
    p ^= 1;
    rep(j, 0, m)
    {
        rep(i, 0, j + 1)
            dp[p][i] = inf;
        rep(i, j + 1, n)
            dp[p][i] = pref[p ^ 1][i] + cnt[p][n - 1] - cnt[p][i];
        if (j == m - 1)
            break;
        rep(i, 0, n)
            if (a[i] == j + 1)
                cnt[p ^ 1][i] = 1;
            else
                cnt[p ^ 1][i] = 0;
        rep(i, 1, n)
            cnt[p ^ 1][i] += cnt[p ^ 1][i - 1];
        rep(i, 0, n)
            pref[p][i] = dp[p][i] + cnt[p ^ 1][i];
        rep(i, 1, n)
            pref[p][i] = min(pref[p][i], pref[p][i - 1]);
        p ^= 1;
    }
    int ans = inf;
    rep(i, 0, n)
        ans = min(ans, dp[p][i]);
    cout << ans << endl;
    return 0;
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("arrayop.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    n *= 3;
    int a[n];
    fill(a, a + n, -1);
    rep(i, 0, n / 3)
    {
        cin >> a[n / 3 + i];
        a[n / 3 + i]--;
        double x;
        cin >> x;
    }
    int p = 0;
    int dp[2][n];
    int pref[2][n];
    int cnt[2][n];
    rep(i, 0, n)
        dp[p][i] = 0;
    rep(i, 0, n)
        if (a[i] == 0)
            cnt[p ^ 1][i] = 1;
        else
            cnt[p ^ 1][i] = 0;
    rep(i, 1, n)
        cnt[p ^ 1][i] += cnt[p ^ 1][i - 1];
    rep(i, 0, n)
        pref[p][i] = dp[p][i] + cnt[p ^ 1][i];
    rep(i, 1, n)
        pref[p][i] = min(pref[p][i], pref[p][i - 1]);
    p ^= 1;
    rep(j, 0, m)
    {
        rep(i, 0, j + 1)
            dp[p][i] = inf;
        rep(i, j + 1, n)
            dp[p][i] = pref[p ^ 1][i - 1] + cnt[p][n - 1] - cnt[p][i];
        if (j == m - 1)
            break;
        rep(i, 0, n)
            if (a[i] == j + 1)
                cnt[p ^ 1][i] = 1;
            else
                cnt[p ^ 1][i] = 0;
        rep(i, 1, n)
            cnt[p ^ 1][i] += cnt[p ^ 1][i - 1];
        rep(i, 0, n)
            pref[p][i] = dp[p][i] + cnt[p ^ 1][i];
        rep(i, 1, n)
            pref[p][i] = min(pref[p][i], pref[p][i - 1]);
        p ^= 1;
    }
    int ans = inf;
    rep(i, 0, n)
        ans = min(ans, dp[p][i]);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int fen[5010];
int N;
void update (int p)
{
	for (int i = p; i <= N; i += i&-i) fen[i]++;
}

int query (int p)
{
	int r = 0;
	for (int i = p; i ; i -= i&-i) r += fen[i];
	return r;
}

int arr [5010];
int anw [2][5010];
const int INF = (1<<15);

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	N = m;
	double te;
	for (int i = 0; i < n; i++) scanf("%d%lf",&arr[i],&te);
	for (int id = n-1; id >= 0; id--)
	{
		bool ac,nx;
		ac = id&1;
		nx = ac^1;
		for (int g = m; g; g--)
		{
			if (arr[id] <= g)
			{
				anw[ac][g] = anw[nx][g];
				continue;
			}
			int left = query(g);
			if (g-1 > 0) left -= query(g-1);
			int w = INF;
			if (left != 0) w = 1+anw[nx][g];
			anw[ac][g] = min(w,left+anw[ac][g+1]);
		}
		update(arr[id]);
	}
	printf("%d\n",anw[0][1]);
}


#include <bits/stdc++.h>
using namespace std;

int fen[5010];
int N;
void update (int p)
{
	for (int i = p; i <= N; i += i&-i) fen[i]++;
}

int query (int p)
{
	int r = 0;
	for (int i = p; i ; i -= i&-i) r += fen[i];
	return r;
}

int arr [5010];
int anw [5010][5010];
const int INF = (1<<15);

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	N = m;
	double te;
	for (int i = 0; i < n; i++) scanf("%d%lf",&arr[i],&te);
	for (int id = n-1; id >= 0; id--)
	{
		int ac,nx;
		ac = id;
		nx = id+1;
		for (int g = m; g; g--)
		{
			if (arr[id] <= g)
			{
				anw[ac][g] = anw[nx][g];
				continue;
			}
			int left = query(g);
			if (g-1 > 0) left -= query(g-1);
			int w = INF;
			if (left != 0) w = 1+anw[nx][g];
			anw[ac][g] = min(w,left+anw[ac][g+1]);
		}
		update(arr[id]);
	}
	printf("%d\n",anw[0][1]);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,dp[5005][5005],a[5005];
double nothing;
ll Rec(ll i,ll last)
{
    if(i==n+1)
        return 0;
    ll &ret=dp[i][last];
    if(~ret)
        return ret;
    ll c1=Rec(i+1,last),c2=0;
    if(a[i]>=last)
        c2=1+Rec(i+1,a[i]);
    return ret=max(c1,c2);
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>m;
    for(ll i=1 ; i<=n ; i++)
        cin>>a[i]>>nothing;
    memset(dp,-1,sizeof dp);
    cout<<n-Rec(1,0)<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair <ll, ll> pll;

const int Max = 5e3 + 10;
const int Mod = 1e9 + 7;
const ll Inf = 1LL << 62;

int n, m, t[Max];
double f[Max];
int dp[Max][Max];

int rec(int pos, int col) {
	if(pos > n) {
		return 0;
	}
	int &ret = dp[pos][col];
	if(~ret) {
		return ret;
	}
	if(t[pos] >= col) {
		ret = max(ret, 1 + rec(pos + 1, t[pos]));
	}
	ret = max(ret, rec(pos + 1, col));
	return ret;
}

int main() {
#ifdef Mr_Emrul
	freopen("inputf.in", "r", stdin);
#endif /// Mr_Emrul

	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> t[i] >> f[i];
	}
	memset(dp, -1, sizeof dp);
	cout << n - rec(1, 0) << endl;
	return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define N 100005
#define M 1000005
#define inf 1000000005

using namespace std;

typedef pair<int,int> ii;
typedef pair<ll,ll> lii;
typedef vector<int> vi;
typedef vector<ii> vii;
const double pi = acos(-1);

int n , m , a[5005] , dp[5005][5005];
double x;

int solve(int i , int prev = n) {
      if(i == n)
            return 0;
      if(dp[i][prev] != -1)
            return dp[i][prev];
      int s1 = solve(i+1 , prev);
      int s2 = 0;
      if(a[i] >= a[prev])
            s2 = solve(i+1 , i) + 1;
      return dp[i][prev] = max(s1 , s2);
}
int main() {
      #ifndef ONLINE_JUDGE
            freopen("in.in", "r", stdin);
            freopen("out.in", "w", stdout);
      #endif

      memset(dp , -1 , sizeof dp);
      cin >> n >> m;
      for(int i = 0; i < n; ++i)
            cin >> a[i] >> x;
      int f = solve(0);
      cout << n - f << endl;
      return 0;
}


#include <bits/stdc++.h>
#define all(v)   ((v).begin()),((v).end())
#define sz(v)    ((int)((v).size()))
#define vi        vector<int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
void mohammed()
{
    ios::sync_with_stdio(0);ios_base::sync_with_stdio(0);cin.tie(0), cout.tie(0);
    //freopen("keys.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
}
int n , arr[5001] , m;
int memo[5001][5001];
int solve(int i, int lastI)
{
    if(i>n)return 0;
    int &ret=memo[i][lastI];
    if(ret!=-1)return ret;
    if(arr[i]>=arr[lastI])ret=solve(i+1 , i)+1;
    return ret=max(solve(i+1 , lastI) , ret);
}
int main()
{
    mohammed();
    cin>>n>>m;
    double x;
    memset(memo , -1 , sizeof memo);
    for(int i=1 ; i<=n ; i++)
    {
        cin>>arr[i]>>x;
    }
    cout<<n-solve(1 , 0);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long n,m,s[(long)1e5],DP[(long)1e5]={};
main()
{
	cin>>n>>m;

	for (int i=1;i<=n;i++)
	{
		double x;
		cin>>s[i]>>x;
	}

	for (int i=1;i<=n;i++)
		DP[i]=i;

	for (int j=1;j<=m;j++)
		for (int i=1;i<=n;i++)
			if(s[i]==j)
				DP[i]=min(DP[i] , DP[i-1]);
			else
				DP[i]=min(DP[i] , DP[i-1] + 1);

	return cout<<DP[n], 0;
}


#include<bits/stdc++.h>
using namespace std;
#define sz(v) (int) v.size()
#define all(v) v.begin(),v.end()
#define filein freopen("hello.txt","r",stdin)
#define fileout freopen("hello.txt","w",stdout)
#define ios  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace(x) cout<< (#x) <<" = "<< x << endl
const long long oo = (long long) 1e9, MOD = 1000000007;
#define eps 1e-9
#define clr(x,val)  memset(x,val,sizeof(x))
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int n, m;
int a[5000 + 9];
int memo[5000 + 9][5000 + 9];

int solve(int idx, int last) {
	if (idx == n) {
		return 0;
	}
	int& ret = memo[idx][last];
	if (~ret)
		return ret;
	ret = 0;
	if (a[idx] >= last)
		ret = max(ret, 1 + solve(idx + 1, max(last, a[idx])));
	ret = max(ret, solve(idx + 1, last));
	return ret;
}

int main() {

	ios;

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		double x;
		cin >> a[i] >> x;
	}

	clr(memo, -1);

	cout << n-solve(0, 0);

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

ll n,m,ar[5001],vis[5001];
double pos;

ll go(ll idx)
{
	if(idx==m+1)
	return 0;
	ll ans=0,cnt1=0,cnt2=0,tmp=0;
	for(ll i=1;i<=n;++i)
	{
		if(vis[i]==0){
		if(ar[i]==idx)
		{
			vis[i]=1;
			cnt1+=tmp;
			if(cnt1>0 || cnt2>0 || tmp>0)
			 cnt2++;
			 tmp=0;
		}
		else
		{
			tmp++;
		}
	}
	}
	//cout<<"aay "<<cnt1<<" "<<cnt2<<endl;
	return (min(cnt1,cnt2) + go(idx+1));
}
int main()
{
	cin>>n>>m;
	//memset(dp,-1,sizeof(dp));
	memset(vis,0,sizeof(vis));
	for(ll i=1;i<=n;++i)
	{
		cin>>ar[i]>>pos;
	}
	cout<<go(1)<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back

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

	ll n,k;
	cin>>n>>k;
	double tmp;
	ll ar[n+1];
	for(ll i=1;i<=n;++i)
        cin>>ar[i]>>tmp;
    ll dp[n+1],ans=0;
    for(ll i=1;i<=n;++i)
    {
        dp[i]=1;
        for(ll j=i-1;j>=1;j--)
        {
            if(ar[i]>=ar[j])
                dp[i]=max(dp[i],dp[j]+1);
        }
        ans=max(ans,dp[i]);
        //cout<<"aaya "<<dp[i]<<endl;
    }
    cout<<n-ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("kmp.gir","r",stdin);freopen ("kmp.cik","w",stdout);
#define mod 1000000009
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,ar[N],sum,a,b,dp[N],top2,last,tut[N],tutmac;

pair<ll,double> p[N];

bool cmp(pair<ll,double> a,pair<ll,double> b)
{
	if(a.se<b.se)
		return 1;
	return 0;
}

ll f()
{
	fo(i,1,n)
	{
		ll top=0;
		fo(j,1,i-1)
		{
			if(ar[i]>=ar[j])
				top=max(top,dp[j]);
		}
		dp[i]=top+1;
	}
	fo(i,1,n)
	{
		sum=max(sum,dp[i]);
		// cout<<dp[i]<<sp;
	}
	// cout<<endl;
	return sum;
}

int main()
{
	fast;
	cin>>n>>m;
	fo(i,1,n)
		cin>>p[i].fi>>p[i].se;
	sort(p+1,p+n+1,cmp);
	// fo(i,1,n)
	// 	cout<<p[i].fi<<sp;
	// cout<<endl;
	fo(i,1,n)
		ar[i]=p[i].fi;
	cout<<n-f();

}

/*     cd onedrive\desktop\kod
cls

*/


#include<bits/stdc++.h>
#define ll int
#define dbg(x) cerr<< #x <<" is "<<x<<endl;
using namespace std;
int main()
{
    ll i,j,k,l,n,m,ans=0,temp=0;
    cin>>n>>m;
    double dp;
    vector<ll>v;
    for(i=1;i<=n;i++)
    {
        cin>>j>>dp;
        v.push_back(j);
    }
//    for(i=0;i<n;i++)
//        cout<<v[i]<<" ";
//    cout<<endl;
    vector<ll>trial;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        if(v[i]>=trial.back())
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        auto pos=upper_bound(trial.begin(),trial.end(),v[i]);
        ll dis=distance(trial.begin(),pos);
        trial[dis]=v[i];
    }
    cout<<(n-ans)<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cerr<< #x <<" is "<<x<<endl;
using namespace std;
class gc
{
    public: bool operator()(pair<ll,double>p1,pair<ll,double>p2)
    {
        return(p1.second<=p2.second);
    }
};
int main()
{
    ll i,j,k,l,n,m,ans=0,temp=0;
    cin>>n>>m;
    set<pair<ll,double>,gc>s;
    double dp;
    for(i=1;i<=n;i++)
    {
        cin>>j>>dp;
        s.insert(make_pair(j,dp));
    }
    vector<ll>v;
    for(auto pos=s.begin();pos!=s.end();++pos)
    {
        v.push_back(pos->first);
    }
//    for(i=0;i<n;i++)
//        cout<<v[i]<<" ";
//    cout<<endl;
    vector<ll>trial;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        if(v[i]>=trial.back())
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        auto pos=upper_bound(trial.begin(),trial.end(),v[i]);
        ll dis=distance(trial.begin(),pos);
        trial[dis]=v[i];
    }
    cout<<(n-ans)<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cerr<< #x <<" is "<<x<<endl;
using namespace std;
int main()
{
    ll i,j,k,l,n,m,ans=0,temp=0;
    cin>>n>>m;
    double dp;
    vector<ll>v;
    for(i=1;i<=n;i++)
    {
        cin>>j>>dp;
        v.push_back(j);
    }
//    for(i=0;i<n;i++)
//        cout<<v[i]<<" ";
//    cout<<endl;
    vector<ll>trial;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        if(v[i]>=trial.back())
        {
            trial.push_back(v[i]);
            ans++;
            continue;
        }
        auto pos=upper_bound(trial.begin(),trial.end(),v[i]);
        ll dis=distance(trial.begin(),pos);
        trial[dis]=v[i];
    }
    cout<<(n-ans)<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n,m;
int s[5005];
int dp[5005];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		double f;
		cin>>s[i]>>f;
	}
	for(int i=1;i<=n;i++)
	{
		dp[i]=1;
		for(int j=1;j<i;j++)
			if(s[j]<=s[i])
				dp[i]=max(dp[i],dp[j]+1);
	}
	cout<<n-*max_element(dp+1,dp+n+1)<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) int x; cin>>x;
#define sin(s) string s; cin>>s;
#define ll long long
#define lin(x) ll x; cin>>x;
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define pb push_back
#define re(i,n) for(int i=0; i<n; i++)
#define pe(i,a,b) for(int i=a; i<=b; i++)
#define rre(i,n) for(int i=n-1; i>-1; i--)
#define mp make_pair
#define pii pair<ll,ll>
#define endl "\n"
#define pi 3.1415926536
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define mod 1000000007
#define inf LLONG_MAX
#define ninf -INT_MAX
/////////////////////////////////////////////////////////////////////////////////

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
        return i.first<j.first;
}
/////////////////////////////////////////////////////////////////////////////////
//vi v;
int ncr(int n, int k)
{
        if(n<k)
                return 0;
        int C[n + 1][k + 1];
        int i, j;
        for (i = 0; i <= n; i++)
        {
                for (j = 0; j <= min(i, k); j++)
                {
                        if (j == 0 || j == i)
                                C[i][j] = 1;
                        else
                                C[i][j] = (C[i - 1][j - 1] + C[i - 1][j])%mod;
                }
        }
        return C[n][k];
}
////////////////////////////////////////////////////////////////////////////
ll modpowIter(ll a, ll b, ll c)
{
        ll ans=1;
        while(b != 0)
        {
                if(b%2 == 1)
                ans=(ans*a)%inf;
                a=(a*a)%inf;
                b /= 2;
        }
        return ans;
}
///////////////////////////////////////////////////////////////////////////////
string intobin(int n)
{
        string s="";
        if(n==0)
                s="0";
        while(n)
        {
                if(n%2)
                        s="1"+s;
                else
                        s="0"+s;
                n/=2;
        }
        return s;
}

////////////////////////////////////////////////////////////////////////////////

int bintoin(string s)
{
        ll n=0;
        vll v;
        v.pb(1);
        re(i,400)
        {
                v.pb((v[v.size()-1]*2)%1000003);
        }
        rre(i,s.length())
        {
                n=(n+(s[i]-'0')*v[s.length()-i-1])%1000003;
                //cout<<v[s.length()-i-1]<<endl;
        }
        return n;
}
//////////////////////////////////////////////////////////////////////////////////
ll nc2(ll n, ll k)
{
        if(n<k)
                return 0;
        return (n*(n-1))/2;
}
///////////////////////////////////////////////////////////////////////////////////
bool prime[1000001];
void SieveOfEratosthenes(int n)
{
        memset(prime, true, sizeof(prime));
        for (int p=2; p*p<=n; p++)
        {
                if (prime[p] == true)
                {
                        for (int i=p*p; i<=n; i += p)
                        prime[i] = false;
                }
        }
        /*for (int p=2; p<=n; p++)
                if (prime[p])
                        v.pb(p);  */
}
///////////////////////////////////////////////////////////////////////////////////

int main()
{
        in(n)
        in(m)
        int arr[n];
        double b[n];
        re(i,n)
        {
                cin>>arr[i]>>b[i];
        }
        int dp[n][4];
        dp[0][0]=arr[0];
        dp[0][1]=1;
        dp[0][2]=0;
        dp[0][3]=0;
        pe(i,1,n-1)
        {
                //cout<<arr[i]<<" //// "<<dp[i-1][0]<<endl;
                //cout<<arr[i]<<" ''' "<<dp[i-1][2]<<endl;
                if(arr[i]>=dp[i-1][0] && arr[i]>=dp[i-1][2])
                {
                        dp[i][0]=arr[i];
                        if(dp[i-1][1]>dp[i-1][3])
                        {
                                dp[i][1]=dp[i-1][1]+1;
                        }
                        else
                        {
                                dp[i][1]=dp[i-1][3]+1;
                        }
                }
                else if(arr[i]>=dp[i-1][0])
                {
                        //cout<<arr[i]<<" ++++ "<<dp[i-1][0]<<endl;
                        dp[i][0]=arr[i];
                        dp[i][1]=dp[i-1][1]+1;
                }
                else if(arr[i]>=dp[i-1][2])
                {
                        //cout<<arr[i]<<" ---- "<<dp[i-1][2]<<endl;
                        dp[i][0]=arr[i];
                        dp[i][1]=dp[i-1][3]+1;
                }
                else
                {
                        dp[i][0]=arr[i];
                        dp[i][1]=1;
                }
                if(dp[i-1][1]>dp[i-1][3])
                {
                        dp[i][3]=dp[i-1][1];
                        dp[i][2]=dp[i-1][0];
                }
                else if(dp[i-1][1]<dp[i-1][3])
                {
                        dp[i][3]=dp[i-1][3];
                        dp[i][2]=dp[i-1][2];
                }
                else
                {
                        dp[i][3]=dp[i-1][3];
                        if(dp[i-1][0]<dp[i-1][2])
                        {
                                dp[i][2]=dp[i-1][0];
                        }
                        else
                        {
                                dp[i][2]=dp[i-1][2];
                        }
                }
        }
        //re(i,n)
        //cout<<dp[i][0]<<" "<<dp[i][1]<<' '<<dp[i][2]<<' '<<dp[i][3]<<endl;
        cout<<n-max(dp[n-1][1],dp[n-1][3]);
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define in(x) int x; cin>>x;
#define sin(s) string s; cin>>s;
#define ll long long
#define lin(x) ll x; cin>>x;
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define pb push_back
#define re(i,n) for(int i=0; i<n; i++)
#define pe(i,a,b) for(int i=a; i<=b; i++)
#define rre(i,n) for(int i=n-1; i>-1; i--)
#define mp make_pair
#define pii pair<ll,ll>
#define endl "\n"
#define pi 3.1415926536
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define mod 1000000007
#define inf LLONG_MAX
#define ninf -INT_MAX
/////////////////////////////////////////////////////////////////////////////////

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
        return i.first<j.first;
}
/////////////////////////////////////////////////////////////////////////////////
//vi v;
int ncr(int n, int k)
{
        if(n<k)
                return 0;
        int C[n + 1][k + 1];
        int i, j;
        for (i = 0; i <= n; i++)
        {
                for (j = 0; j <= min(i, k); j++)
                {
                        if (j == 0 || j == i)
                                C[i][j] = 1;
                        else
                                C[i][j] = (C[i - 1][j - 1] + C[i - 1][j])%mod;
                }
        }
        return C[n][k];
}
////////////////////////////////////////////////////////////////////////////
ll modpowIter(ll a, ll b, ll c)
{
        ll ans=1;
        while(b != 0)
        {
                if(b%2 == 1)
                ans=(ans*a)%inf;
                a=(a*a)%inf;
                b /= 2;
        }
        return ans;
}
///////////////////////////////////////////////////////////////////////////////
string intobin(int n)
{
        string s="";
        if(n==0)
                s="0";
        while(n)
        {
                if(n%2)
                        s="1"+s;
                else
                        s="0"+s;
                n/=2;
        }
        return s;
}

////////////////////////////////////////////////////////////////////////////////

int bintoin(string s)
{
        ll n=0;
        vll v;
        v.pb(1);
        re(i,400)
        {
                v.pb((v[v.size()-1]*2)%1000003);
        }
        rre(i,s.length())
        {
                n=(n+(s[i]-'0')*v[s.length()-i-1])%1000003;
                //cout<<v[s.length()-i-1]<<endl;
        }
        return n;
}
//////////////////////////////////////////////////////////////////////////////////
ll nc2(ll n, ll k)
{
        if(n<k)
                return 0;
        return (n*(n-1))/2;
}
///////////////////////////////////////////////////////////////////////////////////
bool prime[1000001];
void SieveOfEratosthenes(int n)
{
        memset(prime, true, sizeof(prime));
        for (int p=2; p*p<=n; p++)
        {
                if (prime[p] == true)
                {
                        for (int i=p*p; i<=n; i += p)
                        prime[i] = false;
                }
        }
        /*for (int p=2; p<=n; p++)
                if (prime[p])
                        v.pb(p);  */
}
///////////////////////////////////////////////////////////////////////////////////

int main()
{
        in(n)
        in(m)
        int arr[n];
        double b[n];
        re(i,n)
        {
                cin>>arr[i]>>b[i];
        }
        int dp[n];
        dp[0]=1;
        pe(i,1,n-1)
        {
                dp[i]=1;
                re(j,i)
                {
                        if(arr[i]>=arr[j] && dp[i]<dp[j]+1)
                                dp[i]=dp[j]+1;
                }
                //cout<<dp[i]<<endl;
        }
        cout<<n-(*max_element(dp,dp+n));
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,s;
    double x;
    cin>>n>>m;
    int seq[n+1];
    int L[n+1];
    for(int i=0; i<n; i++)
    {
        cin>>s>>x;
        seq[i]=s;

    }
    for(int i=0; i<n; i++)
        L[i]=1;
    for(int i=0; i<n; i++)
    {
        for(int j=i+1; j<n; j++)
        {
            if(seq[i]<=seq[j])
            {
                if(L[j]<L[i]+1)
                    L[j]=L[i]+1;
            }
        }
    }
    int maxx=0;
    for(int i=0;i<n;i++){

        if(maxx<L[i])
            maxx=L[i];
    }
cout<<n-maxx<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int dp[5000+20],a[5000+20],n,m,ans;

double d[5000+20];

int main()
{
    cin>>n>>m;

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

    for(int i=0;i<n;i++)
    {
        dp[i]=1;

        for(int j=0;j<i;j++)
            if(a[i]>=a[j])
                dp[i]=max(dp[i],dp[j]+1);
    }

    for(int i=0;i<n;i++)
        ans=max(ans,dp[i]);

    cout<<n-ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=500050;
int arr[maxn];
int pos,m,f[maxn],len,n,ca;
double w;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		scanf("%d%lf",&pos,&w);
		arr[i]=pos;
	}
	len=0;
	f[0]=0;
	for(int i=1;i<=n;i++) {
		if(arr[i]>=f[len]) {
				f[++len]=arr[i];
			continue;
		}
		else {
			int p=upper_bound(f+1,f+len+1,arr[i])-f;
			f[p]=arr[i];
		}
	}
	printf("%d\n",n-len);
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

int n,m;
int dp[5009][5009];
pair<int,double>ara[5009];
int recur(int pos,int last){
    if(pos>=n)return 0;
    int &ans = dp[pos][last];
    if(ans!=-1)return ans;
    int now = ara[pos].ff;
    ans = 1e9;
    if(now<last){
        ans = 1+recur(pos+1,last);
    }
    else if(now>=last){
        ans = recur(pos+1,now);
        ans = min(ans , 1+recur(pos+1,last));
    }
    return ans;
}
int main() {
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%d %lf",&ara[i].ff,&ara[i].ss);
    }
    memset(dp,-1,sizeof dp);
    int ans=recur(0,0);
    cout<<ans<<"\n";
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
mt19937 R(chrono::system_clock().now().time_since_epoch().count());

/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */

int n,m;
int ara[5009];
int main() {
    scanf("%d %d",&n,&m);
    double tmp;
    for(int i=0;i<n;i++){
        scanf("%d %lf",&ara[i],&tmp);
    }
    multiset < int > s;
    multiset < int > :: iterator it;

    for(int i=0;i<n;i++)
    {
        s.insert(ara[i]);
        it = s.upper_bound(ara[i]);
        if(it != s.end())
            s.erase(it);
    }
    cout<<n-s.size()<<"\n";
}


/*
Observe that the coordinates don't matter. Only the order of the points is important.
Let there be some number of points we can replace to achieve the good arrangement. Then all the other points
remain in their positions, so their values must be in increasing order from left to right. Then we must find
the maximum number of points that can remain in their positions, which is the longest non-decreasing subsequence of types
in the input. If the length of this is l, then the answer is n-l.
*/
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int dp[5001];
int a[5001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; double x,get;
	cin >> n >> x;
	for (int i = 0; i < n; i++){
		cin >> a[i] >> get;
	}
	int res = 0;
	for (int i = 0; i < n; i++){
		dp[i] = 1;
		for (int j = 0; j < i; j++){
			if (a[j] <= a[i]){
				dp[i] = max(dp[i],1+dp[j]);
			}
		}
		res = max(res,dp[i]);
	}
	cout << n-res << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
#define FastIO      ios_base::sync_with_stdio(false); cin.tie(0);
#define aPrint(a,b,c)for(int i=b;i<=c;i++)cout<<a[i]<<" ";cout<<endl;
#define vPrint(a)   for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;
#define Case(t)     printf("Case %d: ", t)
#define clr(x,a)    memset(x,a,sizeof(x))
#define debug(x)    cerr<<#x<<" = "<<(x)<<"\n"

#define umap        unordered_map
#define pii         pair<int, int>
#define pll         pair<ll, ll>
#define ff          first
#define ss          second
#define mp          make_pair
#define pb          push_back
#define ppb         pop_back
#define sf          scanf
#define pf          printf
#define all(a)      a.begin(),a.end()
#define allr(a)     a.rbegin(),a.rend()
#define Unique(a)   sort(all(a)), a.erase(unique(all(a)),a.end())
template <class T> inline T bigmod(T b,T p,T M){ll ret=1;for(;p>0;p>>=1){if(p&1) ret=(ret*b)%M;b=(b*b)%M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T lcm(T a,T b){return a*b / gcd<T>(a, b);}
template <class T> inline T power(T b,T p){ll x=1;while(p--)x*=b;return x;}
const ll mod = 1e9 + 7;
const int siz = 202;
/// 'N'+'A'+'E'+'E'+'E'+'M' ///
#define pi        acos(-1.0)//3.1415926535897932
#define inf       1e18
#define MAX       100010
int n, m, arr[MAX];
double x;
int longestNonDecreasingSubsequence(){
    vector<int> seq;
    for(int i=0; i<n; i++){
        int pos = upper_bound(seq.begin(), seq.end(), arr[i]) - seq.begin();
        if(pos == seq.size()) seq.pb(arr[i]);
        else seq[pos] = arr[i];
    }
    return seq.size();
}
int main() {

    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    FastIO;
    cin>>n>>m;
    for(int i=0; i<n; i++) cin>>arr[i]>>x;
    cout<<n-longestNonDecreasingSubsequence()<<endl;

    #ifndef ONLINE_JUDGE
        printf("\n**Time -> %.10fs\n", (double)(clock()-tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const double eps=1e-6,pi=acos(-1);
const int N=5e3+5,M=1e9+7,SEGM=4*N,OO=0x3f3f3f3f;
int t,n,m,k;
int arr[N];
int mem[N][N];
double d;

int solve(int i,int spc){
    if(i==n) return 0;
    int &ret=mem[i][spc];
    if(~ret) return ret;
    if(arr[i]==spc) return solve(i+1,spc);
    if(arr[i]>spc)
        ret=min(solve(i+1,arr[i]),1+solve(i+1,spc));
    else
        ret=1+solve(i+1,spc);
    return ret;
}

int main(){
    //freopen("myfile.txt","w",stdout);
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i)
        scanf("%d%f",arr+i,&d);
    memset(mem,-1,sizeof mem);
    printf("%d",solve(0,1));
    return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

#define maxn 100003

int spec[maxn];
int dp[maxn];
int arr[maxn];
int n,m;

int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif

	ios_base::sync_with_stdio(false);

	cin >> n >> m;

	int x;
	double d;

	for(int i=0;i<n;i++){
		cin >> x >> d;
		spec[x]++;
		arr[i] = x;
	}
	for(int i=1;i<5001;i++){
		dp[i] = dp[i-1] + spec[i];
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		int lowi = dp[arr[i]-1];
		int highi = dp[arr[i]];
		if(i < lowi){
			ans++;
		}
	}
	cout << ans << '\n';

	return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

#define maxn 100003

int spec[maxn];
int dp[maxn];
int arr[maxn];
int n,m;
int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.in","r",stdin);
	#endif

	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	double tmp;
	for(int i=0;i<n;i++){
		cin >> arr[i] >> tmp;
	}
	for(int i=n-1;i>=0;i--){

		dp[i] = 1;
		for(int j=i+1;j<n;j++){
			if(arr[i] <= arr[j]){
				dp[i] = max(dp[i],dp[j]+1);
			}
		}
	}
	int maxime = 0;
	for(int i=0;i<n;i++){
		maxime = max(maxime,dp[i]);
	}
	cout << n - maxime << '\n';

	return 0;
}


// ICPC Champion is here

#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
vector<int> v,v1;
int mem[5009][5009],n,m;

int solve(int i,int j)
{
     if(i==n||j==n)
        return 0;
     int &ret=mem[i][j];

     if(ret!=-1)
        return ret;
     int p1,p2,p3;
     p1=p2=p3=0;
     if(v[i]==v1[j])
     {
        p1=1+solve(i+1,j+1);
     }

     p2= solve(i+1,j);
     p3= solve(i,j+1);

   return ret= max(p1,max(p2,p3));

}

int main()
{

    cin>>n>>m;
    int s;
    double x;
    for(int i=0;i<n;i++)
    {
        cin>>s>>x;
        v.pb(s);
    }
    v1=v;
    sort(all(v1));
    clr(mem,-1);
    cout<<n-solve(0,0)<<endl;

}


// ICPC Champion is here

#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-10);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
ll getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void M(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
vector<int> v;
int mem[5009][5009],n,m;

int solve(int id,int last)
{
     if(id==n)
        return 0;
     int &ret=mem[id][last];

     if(ret!=-1)
        return ret;

     int p1=INT_MAX,p2;
    if(last==v[id]-1||last==m+1||last==v[id])
    {
       p1= solve(id+1,v[id]);
    }

      p2= 1+solve(id+1,last);

    return ret=min(p1,p2);
}

int main()
{

    cin>>n>>m;
    int s;
    double x;
    for(int i=0;i<n;i++)
    {
        cin>>s>>x;
        v.pb(s);
    }
    clr(mem,-1);
    cout<<solve(0,m+1)<<endl;

}


#include<bits/stdc++.h>
using namespace std;
long long i,j,k,l,n,m,x,y,s;
long long a[200005],b[200005];

main(){
 cin>>n>>k;
    for(i=1; i<=n; i++)
    {cin>>a[i]>>k;
    }
    for(i=1; i<=n; i++)
    {
        x=0;
      for(j=1; j<i; j++)
      if (a[j]<=a[i]){ x=max(x,b[j]);}
      b[i]=x+1;
    }
    for(i=1; i<=n; i++) y=max(y,b[i]);
    cout<<n-y;
}


#include<bits/stdc++.h>
using namespace std;
long long i,j,l,n,m,x,y,s;
long long a[200005],b[200005];
double k;
main(){
 cin>>n>>k;
    for(i=1; i<=n; i++)
    {cin>>a[i]>>k;
    }
    for(i=1; i<=n; i++)
    {
        x=0;
      for(j=1; j<i; j++)
      if (a[j]<=a[i]){ x=max(x,b[j]);}
      b[i]=x+1;
    }
    for(i=1; i<=n; i++) y=max(y,b[i]);
    cout<<n-y;
}


#include <iostream>
using namespace std;
int Array[5005];
int dp[5005];

int main(){
	int N , m , i , j;
	double Num;
	scanf( "%d%d" , &N , &m );

	for( i = 1 ; i <= N ; ++i )
		scanf( "%d%lf" , Array + i , &Num );

	int Ans = N - 1;
	dp[1] = 1;

	for( i = 2 ; i <= N ; ++i ){
		dp[i] = 1;

		for( j = 1 ; j <= i - 1 ; ++j ){
			if( Array[j] <= Array[i] )
				dp[i] = max( dp[i] , dp[j] + 1 );
		}

		Ans = min( Ans , N - dp[i] );
	}

	printf( "%d\n" , Ans );
	return 0;
}