using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VKCupB
{
    class Program
    {
        public interface IReader
        {
            string GetNextLine();
        }

        public class ConsoleReader : IReader
        {
            public string GetNextLine()
            {
                return Console.ReadLine();
            }
        }

        public class Solver
        {
            private readonly IReader _reader;

            public Solver(IReader reader)
            {
                _reader = reader;
            }

            public struct TupleInt
            {
                public int SumWidth { get; private set; }
                public int MaxHeight { get; private set; }

                public void UpdateWidth(int width)
                {
                    SumWidth += width;
                }

                public void UpdateHeight(int value)
                {
                    if (MaxHeight == 0)
                    {
                        MaxHeight = value;
                    }
                    else
                    {
                        MaxHeight = Math.Max(MaxHeight, value);
                    }
                }
            }

            public void Solve()
            {
                int n = Convert.ToInt32(_reader.GetNextLine());

                Tuple<int, int>[] data = new Tuple<int, int>[n];
                TupleInt[] b = new TupleInt[n];

                for (int i = 0; i < n; i++)
                {
                    var inputData = _reader.GetNextLine().Split(' ');
                    data[i] = Tuple.Create(
                        Convert.ToInt32(inputData[0]),
                        Convert.ToInt32(inputData[1]));
                }

                int sumWidth = 0;
                int maxHeight = Int32.MinValue, prevMaxHeight = Int32.MinValue;

                for (int i = 0; i < n; i++)
                {
                    var cur = data[i];
                    sumWidth += cur.Item1;
                    maxHeight = Math.Max(maxHeight, cur.Item2);
                }

                for (int i = 0; i < n; i++)
                {
                    if (data[i].Item2 != maxHeight)
                    {
                        prevMaxHeight = Math.Max(prevMaxHeight, data[i].Item2);
                    }
                }

                for (int i = 0; i < n; i++)
                {
                    var cur = data[i];
                    int width = sumWidth - cur.Item1;
                    int height = cur.Item2 == maxHeight ? prevMaxHeight : maxHeight;

                    Console.Write(width * height);
                    if (i != n - 1)
                    {
                        Console.Write(' ');
                    }
                }
            }
        }

        static void Main(string[] args)
        {
            new Solver(new ConsoleReader()).Solve();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VKCupB
{
    class Program
    {
        public interface IReader
        {
            string GetNextLine();
        }

        public class ConsoleReader : IReader
        {
            public string GetNextLine()
            {
                return Console.ReadLine();
            }
        }

        public class Solver
        {
            private readonly IReader _reader;

            public Solver(IReader reader)
            {
                _reader = reader;
            }

            public struct TupleInt
            {
                public int SumWidth { get; private set; }
                public int MaxHeight { get; private set; }

                public void UpdateWidth(int width)
                {
                    SumWidth += width;
                }

                public void UpdateHeight(int value)
                {
                    if (MaxHeight == 0)
                    {
                        MaxHeight = value;
                    }
                    else
                    {
                        MaxHeight = Math.Max(MaxHeight, value);
                    }
                }
            }

            public List<int> Solve()
            {
                int n = Convert.ToInt32(_reader.GetNextLine());

                Tuple<int, int>[] data = new Tuple<int, int>[n];
                TupleInt[] b = new TupleInt[n];

                for (int i = 0; i< n;i++)
                {
                    var inputData = _reader.GetNextLine().Split(' ');
                    data[i] = Tuple.Create(
                        Convert.ToInt32(inputData[0]),
                        Convert.ToInt32(inputData[1]));
                }

                for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < n; j++)
                        {
                            if (i == j) continue;

                            b[j].UpdateWidth(data[i].Item1);
                            b[j].UpdateHeight(data[i].Item2);
                        }
                    }

                return b.Select(v => v.MaxHeight * v.SumWidth).ToList();
            }
        }

        static void Main(string[] args)
        {
            var data1 = new Solver(new ConsoleReader()).Solve();
            Console.WriteLine(String.Join(" ", data1));
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Foto
{
    class Program
    {
        static void Main(string[] args)
        {
            var __data = new Data();
            __data.Load();

            var __sb = new StringBuilder(10000000);
            foreach (var __frend in __data.frends)
            {
                var __res = Calc(__data, __frend);

                //__sb.Append(__res).Append(' ');
            }
            Console.Write(__sb.ToString());
        }

        static int Calc(Data data, Frend fotoFrend)
        {
            int __w = data.W - fotoFrend.w;
            int __h = data.H;
            if (fotoFrend.h == __h)
                __h = data.Hnext;

            return __h * __w;
        }

        class Data
        {
            public Frend[] frends { get; protected set; }

            public int W { get; protected set; }
            public int H { get; protected set; }
            public int Hnext { get; protected set; }

            public void Load()
            {
                InputStorage.readInput();
                int __n = InputStorage.getNextInt();
                frends = new Frend[__n];
                for (int __i = 0; __i < __n; __i++)
                {
//                    InputStorage.readInput();
//                    var __frend = new Frend(InputStorage.getNextInt(), InputStorage.getNextInt());
                    String __line = Console.ReadLine();
                    int __splitIdx = __line.IndexOf(' ');
                    int __w = Int32.Parse(__line.Substring(0, __splitIdx));
                    int __h = Int32.Parse(__line.Substring(__splitIdx + 1, __line.Length - __splitIdx - 1));
                    var __frend = new Frend(__w, __h);

                    frends[__i] = __frend;

                    W += __frend.w;
                    if (H < __frend.h)
                    {
                        Hnext = H;
                        H = __frend.h;
                    }
                    else
                        if (Hnext < __frend.h)
                            Hnext = __frend.h;
                }
            }
        }

        class Frend
        {
            public int w { get; set; }
            public int h { get; set; }

            public Frend(int w, int h)
            {
                this.w = w;
                this.h = h;
            }
        }

        static class InputStorage
        {
            static string _allInput;

            static string _lastInput;
            static string[] _lastInputAr;
            static int _lastInputIndex;
            static char[] _chSepAr = new char[] { ' ' };

            const string _lineBreak = "@@@";

            public static void readInput()
            {
                _lastInput = Console.ReadLine();
                _lastInputAr = _lastInput.Split(_chSepAr);
                _lastInputIndex = 0;

                if (!string.IsNullOrEmpty(_allInput))
                    _allInput += _lineBreak;

                _allInput += _lastInput;
            }

            static string getNextString()
            {
                return _lastInputAr[_lastInputIndex++];
            }

            public static String getLastInput()
            {
                return _lastInput;
            }

            public static int getNextInt()
            {
                string __str = getNextString();
                return int.Parse(__str);
            }

            public static char getNextCharFromString()
            {
                char __ch = _lastInput[_lastInputIndex++];
                return __ch;
            }

            public static void outToConsole()
            {
                Console.WriteLine(_allInput);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Foto
{
    class Program
    {
        static void Main(string[] args)
        {
            var __data = new Data();
            __data.Load();

            foreach (var __frend in __data.frends)
            {
                var __res = Calc(__data, __frend);

                Console.Write(__res);
                Console.Write(' ');
            }
        }

        static int Calc(Data data, Frend fotoFrend)
        {
            int __w = data.W - fotoFrend.w;
            int __h = data.H;
            if (fotoFrend.h == __h)
                __h = data.frends.Where(o => o != fotoFrend).Max(o => o.h);

            return __h * __w;
        }

        class Data
        {
            public Frend[] frends { get; protected set; }

            public int W { get; protected set; }
            public int H { get; protected set; }

            public void Load()
            {
                InputStorage.readInput();
                int __n = InputStorage.getNextInt();
                frends = new Frend[__n];
                for (int __i = 0; __i < __n; __i++)
                {
//                    InputStorage.readInput();
//                    var __frend = new Frend(InputStorage.getNextInt(), InputStorage.getNextInt());
                    String __line = Console.ReadLine();
                    int __splitIdx = __line.IndexOf(' ');
                    int __w = Int32.Parse(__line.Substring(0, __splitIdx));
                    int __h = Int32.Parse(__line.Substring(__splitIdx + 1, __line.Length - __splitIdx - 1));
                    var __frend = new Frend(__w, __h);

                    frends[__i] = __frend;

                    W += __frend.w;
                    H = H < __frend.h ? __frend.h : H;
                }
            }
        }

        class Frend
        {
            public int w { get; set; }
            public int h { get; set; }

            public Frend(int w, int h)
            {
                this.w = w;
                this.h = h;
            }
        }

        static class InputStorage
        {
            static string _allInput;

            static string _lastInput;
            static string[] _lastInputAr;
            static int _lastInputIndex;
            static char[] _chSepAr = new char[] { ' ' };

            const string _lineBreak = "@@@";

            public static void readInput()
            {
                _lastInput = Console.ReadLine();
                _lastInputAr = _lastInput.Split(_chSepAr);
                _lastInputIndex = 0;

                if (!string.IsNullOrEmpty(_allInput))
                    _allInput += _lineBreak;

                _allInput += _lastInput;
            }

            static string getNextString()
            {
                return _lastInputAr[_lastInputIndex++];
            }

            public static String getLastInput()
            {
                return _lastInput;
            }

            public static int getNextInt()
            {
                string __str = getNextString();
                return int.Parse(__str);
            }

            public static char getNextCharFromString()
            {
                char __ch = _lastInput[_lastInputIndex++];
                return __ch;
            }

            public static void outToConsole()
            {
                Console.WriteLine(_allInput);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Foto
{
    class Program
    {
        static void Main(string[] args)
        {
            var __data = new Data();
            __data.Load();

            var __sb = new StringBuilder(10000000);
            foreach (var __frend in __data.frends)
            {
                var __res = Calc(__data, __frend);

                //__sb.Append(__res).Append(' ');
            }
            Console.Write(__sb.ToString());
        }

        static int Calc(Data data, Frend fotoFrend)
        {
            int __w = data.W - fotoFrend.w;
            int __h = data.H;
            if (fotoFrend.h == __h)
                __h = data.Hnext;

            return __h * __w;
        }

        class Data
        {
            public Frend[] frends { get; protected set; }

            public int W { get; protected set; }
            public int H { get; protected set; }
            public int Hnext { get; protected set; }

            public void Load()
            {
                InputStorage.readInput();
                int __n = InputStorage.getNextInt();
                frends = new Frend[__n];
                for (int __i = 0; __i < __n; __i++)
                {
//                    InputStorage.readInput();
//                    var __frend = new Frend(InputStorage.getNextInt(), InputStorage.getNextInt());
                    String __line = Console.ReadLine();
                    int __splitIdx = __line.IndexOf(' ');
                    int __w = Int32.Parse(__line.Substring(0, __splitIdx));
                    int __h = Int32.Parse(__line.Substring(__splitIdx + 1, __line.Length - __splitIdx - 1));
                    var __frend = new Frend(__w, __h);

                    frends[__i] = __frend;

                    W += __frend.w;
                    if (H <= __frend.h)
                    {
                        Hnext = H;
                        H = __frend.h;
                    }
                }
            }
        }

        class Frend
        {
            public int w { get; set; }
            public int h { get; set; }

            public Frend(int w, int h)
            {
                this.w = w;
                this.h = h;
            }
        }

        static class InputStorage
        {
            static string _allInput;

            static string _lastInput;
            static string[] _lastInputAr;
            static int _lastInputIndex;
            static char[] _chSepAr = new char[] { ' ' };

            const string _lineBreak = "@@@";

            public static void readInput()
            {
                _lastInput = Console.ReadLine();
                _lastInputAr = _lastInput.Split(_chSepAr);
                _lastInputIndex = 0;

                if (!string.IsNullOrEmpty(_allInput))
                    _allInput += _lineBreak;

                _allInput += _lastInput;
            }

            static string getNextString()
            {
                return _lastInputAr[_lastInputIndex++];
            }

            public static String getLastInput()
            {
                return _lastInput;
            }

            public static int getNextInt()
            {
                string __str = getNextString();
                return int.Parse(__str);
            }

            public static char getNextCharFromString()
            {
                char __ch = _lastInput[_lastInputIndex++];
                return __ch;
            }

            public static void outToConsole()
            {
                Console.WriteLine(_allInput);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Foto
{
    class Program
    {
        static void Main(string[] args)
        {
            var __data = new Data();
            __data.Load();

            foreach (var __frend in __data.frends)
            {
                var __res = Calc(__data, __frend);

                Console.Write(__res);
                Console.Write(' ');
            }
        }

        static int Calc(Data data, Frend fotoFrend)
        {
            int __w = data.W - fotoFrend.w;
            int __h = data.H;
            if (fotoFrend.h == __h)
                __h = data.frends.Where(o => o != fotoFrend).Max(o => o.h);

            return __h * __w;
        }

        class Data
        {
            public Frend[] frends { get; protected set; }

            public int W { get; protected set; }
            public int H { get; protected set; }

            public void Load()
            {
                InputStorage.readInput();
                int __n = InputStorage.getNextInt();
                frends = new Frend[__n];
                for (int __i = 0; __i < __n; __i++)
                {
                    InputStorage.readInput();
                    var __frend = new Frend(InputStorage.getNextInt(), InputStorage.getNextInt());
                    frends[__i] = __frend;

                    W += __frend.w;
                    H = H < __frend.h ? __frend.h : H;
                }
            }
        }

        class Frend
        {
            public int w { get; set; }
            public int h { get; set; }

            public Frend(int w, int h)
            {
                this.w = w;
                this.h = h;
            }
        }

        static class InputStorage
        {
            static string _allInput;

            static string _lastInput;
            static string[] _lastInputAr;
            static int _lastInputIndex;
            static char[] _chSepAr = new char[] { ' ' };

            const string _lineBreak = "@@@";

            public static void readInput()
            {
                _lastInput = Console.ReadLine();
                _lastInputAr = _lastInput.Split(_chSepAr);
                _lastInputIndex = 0;

                if (!string.IsNullOrEmpty(_allInput))
                    _allInput += _lineBreak;

                _allInput += _lastInput;
            }

            static string getNextString()
            {
                return _lastInputAr[_lastInputIndex++];
            }

            public static String getLastInput()
            {
                return _lastInput;
            }

            public static int getNextInt()
            {
                string __str = getNextString();
                return int.Parse(__str);
            }

            public static char getNextCharFromString()
            {
                char __ch = _lastInput[_lastInputIndex++];
                return __ch;
            }

            public static void outToConsole()
            {
                Console.WriteLine(_allInput);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Foto
{
    class Program
    {
        static void Main(string[] args)
        {
            var __data = new Data();
            __data.Load();

            var __sb = new StringBuilder(10000000);
            foreach (var __frend in __data.frends)
            {
                var __res = Calc(__data, __frend);

                __sb.Append(__res).Append(' ');
            }
            Console.Write(__sb.ToString());
        }

        static int Calc(Data data, Frend fotoFrend)
        {
            int __w = data.W - fotoFrend.w;
            int __h = data.H;
            if (fotoFrend.h == __h)
                __h = data.Hnext;

            return __h * __w;
        }

        class Data
        {
            public Frend[] frends { get; protected set; }

            public int W { get; protected set; }
            public int H { get; protected set; }
            public int Hnext { get; protected set; }

            public void Load()
            {
                InputStorage.readInput();
                int __n = InputStorage.getNextInt();
                frends = new Frend[__n];
                for (int __i = 0; __i < __n; __i++)
                {
//                    InputStorage.readInput();
//                    var __frend = new Frend(InputStorage.getNextInt(), InputStorage.getNextInt());
                    String __line = Console.ReadLine();
                    int __splitIdx = __line.IndexOf(' ');
                    int __w = Int32.Parse(__line.Substring(0, __splitIdx));
                    int __h = Int32.Parse(__line.Substring(__splitIdx + 1, __line.Length - __splitIdx - 1));
                    var __frend = new Frend(__w, __h);

                    frends[__i] = __frend;

                    W += __frend.w;
                    if (H < __frend.h)
                    {
                        Hnext = H;
                        H = __frend.h;
                    }
                    else
                        if (Hnext < __frend.h)
                            Hnext = __frend.h;
                }
            }
        }

        class Frend
        {
            public int w { get; set; }
            public int h { get; set; }

            public Frend(int w, int h)
            {
                this.w = w;
                this.h = h;
            }
        }

        static class InputStorage
        {
            static string _allInput;

            static string _lastInput;
            static string[] _lastInputAr;
            static int _lastInputIndex;
            static char[] _chSepAr = new char[] { ' ' };

            const string _lineBreak = "@@@";

            public static void readInput()
            {
                _lastInput = Console.ReadLine();
                _lastInputAr = _lastInput.Split(_chSepAr);
                _lastInputIndex = 0;

                if (!string.IsNullOrEmpty(_allInput))
                    _allInput += _lineBreak;

                _allInput += _lastInput;
            }

            static string getNextString()
            {
                return _lastInputAr[_lastInputIndex++];
            }

            public static String getLastInput()
            {
                return _lastInput;
            }

            public static int getNextInt()
            {
                string __str = getNextString();
                return int.Parse(__str);
            }

            public static char getNextCharFromString()
            {
                char __ch = _lastInput[_lastInputIndex++];
                return __ch;
            }

            public static void outToConsole()
            {
                Console.WriteLine(_allInput);
            }
        }
    }
}


using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Net.Sockets;
using System.Xml;
using System.Diagnostics;
using System.Linq;

namespace mccmeSolution
{
    class Program
    {
        #region IO
        public delegate ReadDelegate<T> ReadDelegate<T>(out T value);
        public delegate bool ParserDelegate<T>(string word, out T item);

        public class Input : IDisposable
        {
            private static EventArgs DefaultEventArgs = new EventArgs();

            public TextReader TextReader { get; private set; }

            public event EventHandler OnEndOfStream;
            public event EventHandler OnParseError;
            public event EventHandler OnReadError;

            public bool CanRead { get; private set; }
            public bool ThrowExceptions { get; set; }

            string line = string.Empty;
            int pos = 0;

            static EventHandler emptyHandler;

            public Input(string path)
                : this(File.OpenRead(path))
            {
            }
            public Input(Stream s)
                : this(new StreamReader(s))
            {

            }
            public Input(TextReader tr)
            {
                TextReader = tr;

                if (emptyHandler == null)
                    emptyHandler = (a, b) => { };

                OnEndOfStream = emptyHandler;
                OnParseError = emptyHandler;
                OnReadError = emptyHandler;

                CanRead = true;
            }

            public static implicit operator Input(Stream s)
            {
                return new Input(s);
            }
            public static implicit operator Input(TextReader tr)
            {
                return new Input(tr);
            }

            private bool ReadStream()
            {
                if (!CanRead) return false;
                if (pos < line.Length) return true;

                Clear();

                string s = TextReader.ReadLine();
                if (s == null)
                {
                    CanRead = false;
                    return false;
                }

                line = s;
                return true;
            }

            public ReadDelegate<T> r<T>(out T value)
            {
                value = ReadData<T>();
                return r;
            }

            public void SkipChar()
            {
                if (pos < line.Length) pos++;
                else
                {
                    ReadStream();
                }
            }
            public void SkipChars(int length)
            {
                while (length > 0)
                {
                    int dt = line.Length - pos;
                    if (dt <= 0)
                    {
                        length--;
                        if (!ReadStream()) return;
                    }
                    dt = Math.Min(length, dt);
                    pos += dt;
                    length -= dt;
                }
            }

            public void SkipWhiteSpace()
            {
                while (true)
                {
                    for (; pos < line.Length; pos++)
                    {
                        if (!char.IsWhiteSpace(line[pos])) return;
                    }
                    if (!ReadStream())
                    {
                        OnEndOfStream(this, DefaultEventArgs);
                        return;
                    }
                }
            }
            public bool CanReadData()
            {
                SkipWhiteSpace();
                return CanRead;
            }

            public T[] ReadArray<T>()
            {
                int length = ReadInt32();
                return ReadArray<T>(length);
            }
            public T[] ReadArray<T>(int length)
            {
                ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
                return ReadArray<T>(length, parser);
            }
            public T[] ReadArray<T>(ParserDelegate<T> parser)
            {
                int length = ReadInt32();
                return ReadArray<T>(length, parser);
            }
            public T[] ReadArray<T>(int length, ParserDelegate<T> parser)
            {
                T[] res = new T[length];
                for (int i = 0; i < length; i++)
                {
                    res[i] = ReadData<T>(parser);
                }
                return res;
            }

            public Decimal ReadDecimal()
            {
                return ReadData<Decimal>(Parser.DecimalParser);
            }
            public Double ReadDouble()
            {
                return ReadData<Double>(Parser.DoubleParser);
            }
            public Single ReadSingle()
            {
                return ReadData<Single>(Parser.SingleParser);
            }
            public UInt64 ReadUInt64()
            {
                return ReadData<UInt64>(UInt64.TryParse);
            }
            public UInt32 ReadUInt32()
            {
                return ReadData<UInt32>(UInt32.TryParse);
            }
            public UInt16 ReadUInt16()
            {
                return ReadData<UInt16>(UInt16.TryParse);
            }
            public Int64 ReadInt64()
            {
                return ReadData<Int64>(Int64.TryParse);
            }
            public Int32 ReadInt32()
            {
                return ReadData<Int32>(Int32.TryParse);
            }
            public Int16 ReadInt16()
            {
                return ReadData<Int16>(Int16.TryParse);
            }
            public Boolean ReadYesNo()
            {
                return ReadData<Boolean>(Parser.YesNoParser);
            }
            public Boolean ReadBoolean()
            {
                return ReadData<Boolean>(Boolean.TryParse);
            }
            public Byte ReadByte()
            {
                return ReadData<Byte>(Byte.TryParse);
            }

            private bool ReadCheck()
            {
                if (!CanRead)
                {
                    OnReadError(this, DefaultEventArgs);
                    if (ThrowExceptions)
                    {
                        throw new Exception("!CanRead");
                    }
                    return false;
                }
                return true;
            }
            public T ReadData<T>()
            {
                return ReadData<T>(true);
            }
            public T ReadData<T>(bool skipWhiteSpace)
            {
                ParserDelegate<T> parser = Parser.GetPrimitiveParser<T>();
                return ReadData<T>(parser, skipWhiteSpace);
            }
            public T ReadData<T>(ParserDelegate<T> parser)
            {
                return ReadData<T>(parser, true);
            }
            public T ReadData<T>(ParserDelegate<T> parser, bool skipWhiteSpace)
            {
                if (skipWhiteSpace)
                    SkipWhiteSpace();

                if (!ReadCheck()) return default(T);

                string s = ReadWord(false);

                T res;
                if (!parser.Invoke(s, out res))
                {
                    OnParseError(this, DefaultEventArgs);
                    if (ThrowExceptions)
                    {
                        throw new Exception("!validate, word = " + Output.ToString(s, 256));
                    }
                }
                return res;
            }

            public string ReadWord()
            {
                return ReadWord(true);
            }
            public string ReadWord(bool skipWhiteSpace)
            {
                if (skipWhiteSpace)
                    SkipWhiteSpace();

                if (!ReadCheck()) return string.Empty;

                int from = pos;
                int to = pos;
                for (int i = pos; i < line.Length; i++)
                {
                    if (char.IsWhiteSpace(line[i])) break;
                    to = i + 1;
                }
                pos = to;

                return line.Substring(from, to - from);
            }

            public string ReadLine()
            {
                if (!ReadCheck()) return string.Empty;

                ReadStream();
                string res = line.Substring(pos);
                pos = line.Length;

                return res;
            }

            public void Close()
            {
                TextReader.Close();
            }
            public void Clear()
            {
                pos = 0;
                line = string.Empty;
            }

            private bool disposed = false;
            public void Dispose()
            {
                Dispose(true);
                GC.SuppressFinalize(this);
            }

            protected virtual void Dispose(bool disposing)
            {
                if (!this.disposed)
                {
                    if (disposing)
                    {
                        line = string.Empty;
                        TextReader.Dispose();
                    }
                    disposed = true;
                }
            }
            ~Input()
            {
                Dispose(false);
            }
        }
        public class Output : IDisposable
        {
            static char[] space = new char[] { ' ' };

            public TextWriter TextWriter { get; private set; }
            public bool AutoFlush { get; set; }

            public static string ToString(object obj, int maxLength)
            {
                return ToString(FormatReal(obj), maxLength);
            }
            public static string ToString(string s, int maxLength)
            {
                if (s.Length <= maxLength) return s;
                else return s.Substring(0, maxLength) + "...";
            }
            public static object FormatReal(object v, string format)
            {
                if (v is decimal) return ((decimal)v).ToString(format).Replace(',', '.');
                if (v is double) return ((double)v).ToString(format).Replace(',', '.');
                if (v is float) return ((float)v).ToString(format).Replace(',', '.');

                return v;
            }
            public static object FormatReal(object v)
            {
                if (v is decimal || v is double || v is float)
                {
                    return v.ToString().Replace(',', '.');
                }
                return v;
            }

            public Output()
                : this(new MemoryStream())
            {
            }
            public Output(string path)
                : this(File.Create(path))
            {

            }
            public Output(Stream s)
                : this(new StreamWriter(s))
            {
            }
            public Output(TextWriter tw)
            {
                TextWriter = tw;
            }

            public static implicit operator Output(Stream s)
            {
                return new Output(s);
            }

            public static implicit operator Output(TextWriter tw)
            {
                return new Output(tw);
            }

            public static Output operator +(Output output, object obj)
            {
                output.Write(obj);
                return output;
            }
            public Output WriteArray<T>(params T[] array)
            {
                return WriteArray<T>(array, false);
            }
            public Output WriteArray<T>(T[] array, bool appendLength)
            {
                return WriteArray<T>(array, 0, array.Length, appendLength);
            }
            public Output WriteArray<T>(T[] array, int index, int count)
            {
                return WriteArray<T>(array, index, count, false);
            }
            public Output WriteArray<T>(T[] array, int index, int count, bool appendLength)
            {
                if (index + count > array.Length)
                {
                    string message = string.Format(
                        "Index out of range: {0} + {1} >= {2}",
                        index,
                        count,
                        array.Length);
                    throw new Exception(message);
                }
                if (appendLength)
                {
                    WriteLine(count);
                }
                for (int i = 0; i < count; i++)
                {
                    Write(array[i]);
                    Write(space, 0, space.Length);
                }
                WriteLine();

                return this;
            }
            public Output WriteLine(object obj)
            {
                obj = FormatReal(obj);
                return WriteLine(obj.ToString());
            }
            public Output WriteLine(string format, params object[] args)
            {
                return WriteLine(string.Format(format, args));
            }
            public Output WriteLine(string s)
            {
                return WriteLine(s.ToCharArray());
            }
            public Output WriteLine(char[] buffer)
            {
                return WriteLine(buffer, 0, buffer.Length);
            }
            public Output WriteLine(char[] buffer, int index, int count)
            {
                TextWriter.WriteLine(buffer, index, count);
                if (AutoFlush) TextWriter.Flush();
                return this;
            }
            public Output WriteLine()
            {
                TextWriter.WriteLine();
                if (AutoFlush) TextWriter.Flush();
                return this;
            }
            public Output Write(object obj)
            {
                obj = FormatReal(obj);
                return Write(obj.ToString());
            }
            public Output Write(string format, params object[] args)
            {
                return Write(string.Format(format, args));
            }
            public Output Write(string s)
            {
                return Write(s.ToCharArray());
            }
            public Output Write(char[] buffer)
            {
                return Write(buffer, 0, buffer.Length);
            }
            public Output Write(char[] buffer, int index, int count)
            {
                TextWriter.Write(buffer, index, count);
                if (AutoFlush) TextWriter.Flush();
                return this;
            }

            public void Close()
            {
                TextWriter.Close();
            }
            public void Flush()
            {
                TextWriter.Flush();
            }

            private bool disposed = false;
            public void Dispose()
            {
                Dispose(true);
                GC.SuppressFinalize(this);
            }

            protected virtual void Dispose(bool disposing)
            {
                if (!this.disposed)
                {
                    if (disposing)
                    {
                        TextWriter.Dispose();
                    }
                    disposed = true;
                }
            }
            ~Output()
            {
                Dispose(false);
            }
        }
        public static class Parser
        {
            public static ParserDelegate<T> GetPrimitiveParser<T>()
            {
                if (!typeof(T).IsPrimitive) throw new Exception("Unknown type");
                else if (default(T) is Byte) return new ParserDelegate<Byte>(Byte.TryParse) as ParserDelegate<T>;
                else if (default(T) is Boolean) return new ParserDelegate<Boolean>(Boolean.TryParse) as ParserDelegate<T>;
                else if (default(T) is Int16) return new ParserDelegate<Int16>(Int16.TryParse) as ParserDelegate<T>;
                else if (default(T) is Int32) return new ParserDelegate<Int32>(Int32.TryParse) as ParserDelegate<T>;
                else if (default(T) is Int64) return new ParserDelegate<Int64>(Int64.TryParse) as ParserDelegate<T>;
                else if (default(T) is UInt16) return new ParserDelegate<UInt16>(UInt16.TryParse) as ParserDelegate<T>;
                else if (default(T) is UInt32) return new ParserDelegate<UInt32>(UInt32.TryParse) as ParserDelegate<T>;
                else if (default(T) is UInt64) return new ParserDelegate<UInt64>(UInt64.TryParse) as ParserDelegate<T>;
                else if (default(T) is Single) return new ParserDelegate<Single>(Parser.SingleParser) as ParserDelegate<T>;
                else if (default(T) is Double) return new ParserDelegate<Double>(Parser.DoubleParser) as ParserDelegate<T>;
                else if (default(T) is Decimal) return new ParserDelegate<Decimal>(Parser.DecimalParser) as ParserDelegate<T>;
                else if (default(T) is String) return new ParserDelegate<String>(Parser.StringParser) as ParserDelegate<T>;
                else throw new Exception("Unknown type");
            }
            public static bool YesNoParser(string s, out Boolean result)
            {
                s = s.ToLower();
                if (s == "yes") result = true;
                else if (s == "no") result = false;
                else
                {
                    result = false;
                    return false;
                }
                return true;
            }
            public static bool StringParser(string s, out string result)
            {
                result = s;
                return string.IsNullOrEmpty(s);
            }
            public static bool DecimalParser(string s, out Decimal result)
            {
                return Decimal.TryParse(s.Replace('.', ','), out result);
            }
            public static bool DoubleParser(string s, out Double result)
            {
                return Double.TryParse(s.Replace('.', ','), out result);
            }
            public static bool SingleParser(string s, out Single result)
            {
                return Single.TryParse(s.Replace('.', ','), out result);
            }
        }
        #endregion
        #region Streams
        static string endl = Environment.NewLine;
        static Input cin = new Input(Console.In);
        static Output cout = new Output(Console.Out);
        static Output cerr = new Output(Console.Error);
        #endregion
        #region Time
        //*
        static Stopwatch sw = new Stopwatch();
        static void Start()
        {
            sw.Reset();
            sw.Start();
        }
        static void Restart(string text = "")
        {
            Stop(text);
            Start();
        }
        static void Time(string text = "")
        {
            if (string.IsNullOrEmpty(text))
            {
                cerr.WriteLine(sw.Elapsed);
            }
            else
            {
                cerr.WriteLine(text + ": " + sw.Elapsed);
            }
        }
        static void Stop(string text = "")
        {
            sw.Stop();
            Time(text);
        }
        //*/
        #endregion

        static void SearchMaxHPair(int[] hs, out int first, out int second)
        {
            first = 0;
            second = 0;

            foreach (var h in hs)
            {
                if (h >= first)
                {
                    second = first;
                    first = h;
                    continue;
                }
                if (h > second)
                {
                    second = h;
                }
            }
        }
        static void Main()
        {
            var n = cin.ReadInt32();

            var ws = new int[n];
            var hs = new int[n];
            var ans = new long[n];
            for (var i = 0; i < n; i++)
            {
                ws[i] = cin.ReadInt32();
                hs[i] = cin.ReadInt32();
            }

            int first, second;
            SearchMaxHPair(hs, out first, out second);

            long wsum = ws.Sum();
            for (var i = 0; i < n; i++)
            {
                long h = first;
                if (hs[i] == first)
                {
                    h = second;
                }

                ans[i] = (wsum - ws[i]) * h;
            }

            cout.WriteArray(ans);
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace codeforces
{
	class Program
	{
		public const int Osn = 1000000007;

		public class Pair
		{
			public long First;

			public long Second;
		}

		public class PairComparer : IComparer<Pair>
		{
			public int Compare(Pair x, Pair y)
			{
				if (x.First < y.First || (x.First == y.First && x.Second > y.Second))
					return -1;
				return 1;
			}
		}

		public static long GetGcd(long a, long b)
		{
			while (true)
			{
				if (b == 0)
					return a;
				var a1 = a;
				a = b;
				b = a1 % b;

			}
		}

		public static void WriteYesNo(bool x, string yes = "YES", string no = "NO")
		{
			if (x)
				Console.WriteLine(yes);
			else
			{
				Console.WriteLine(no);
			}
		}

		public static string ReadString()
		{
			return Console.ReadLine();
		}

		public static List<int> ReadListOfInts()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(int.Parse).ToList();
		}

		public static List<long> ReadListOfLongs()
		{
			var s = Console.ReadLine();
			return s.Split(' ').Select(long.Parse).ToList();
		}

		public static int ReadInt()
		{
			var s = Console.ReadLine();
			return int.Parse(s);
		}

		public static long ReadLong()
		{
			var s = Console.ReadLine();
			return long.Parse(s);
		}

		public class Vertex
		{
			public int Was;

			public List<int> Edges;
		}

		public static List<Vertex> Graph = new List<Vertex>();

		public static bool Dfs(int u)
		{
			if (Graph[u].Was == 1) return true;
			if (Graph[u].Was == 2) return false;
			Graph[u].Was = 1;
			foreach (var t in Graph[u].Edges)
			{
				if (Dfs(t)) return true;
			}

			Graph[u].Was = 2;
			return false;
		}

		public static bool IsPrime(int x)
		{
			for (var j = 2; j * j <= x; ++j)
				if (x % j == 0)
					return false;
			return true;
		}

		public class LinkedVertex
		{
			public int Next;

			public int Prev;

			public int Value;
		}

		public static int BinarySearch(List<int> list, int value)
		{
			var l = -1;
			var r = list.Count;
			while (r - l > 1)
			{
				var m = (r + l) / 2;
				if (list[m] >= value)
					r = m;
				else
					l = m;
			}

			return r;
		}

		private static void Main()
		{
			var n = ReadInt();
			var friends = new List<Pair>();
			var mx = 0;
			var mx2 = 0;
			for (var i = 0; i < n; ++i)
			{
				var l = ReadListOfInts();
				if (l[1] >= mx)
				{
					mx2 = mx;
					mx = l[1];
				}
				if (l[1] != mx && l[1] >= mx2)
					mx2 = l[1];
				friends.Add(new Pair {First = l[0], Second = l[1]});
			}
			var sumWidth = friends.Sum(x => x.First);
			for (var i = 0; i < n; ++i)
			{
				Console.Write("{0} ",(sumWidth - friends[i].First) * (friends[i].Second == mx ? mx2 : mx));
			}
			Console.ReadLine();
		}
	}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace vk_cup2
{
    class Program
    {
        static int n, m, m1;
        static int[] w, h;
        static void Main(string[] args)
        {
            n = Convert.ToInt32(Console.ReadLine());
            m = -1;
            m1 = -1;
            int mm = 0, mm1 = 0;
            int sum = 0;
            w = new int[n];
            h = new int[n];
            String t;
            for (int i = 0; i < n; i++) { t = Console.ReadLine(); w[i] = Convert.ToInt32(t.Split(' ')[0]); h[i] = Convert.ToInt32(t.Split(' ')[1]); }
            for (int i = 0; i < n; i++) { sum += w[i]; if (h[i] > m) {  m = h[i]; } }
            for (int i = 0; i < n; i++) {  if ((h[i] > m1)&&(h[i]<m)) { m1 = h[i]; } }
            for (int i = 0; i < n; i++) { if (h[i] == m) { mm++; } if (h[i] == m1) { mm1++; } }
            if (mm > 1)
            {
                for (int i = 0; i < n; i++) { Console.Write((sum - w[i]) * m + " "); }
            }
            else if (mm1 > 1)
            {
                for (int i = 0; i < n; i++) { if (h[i] == m) { Console.Write((sum - w[i]) * m1 + " "); } else Console.Write((sum - w[i]) * m + " "); }
            }
            else
            {
                for (int i = 0; i < n; i++) { if (h[i] == m) { Console.Write((sum - w[i]) * m1 + " "); } else { Console.Write((sum - w[i]) * m + " "); } }
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace Photo
{
    public sealed class Program
    {
        public static void Main(string[] args)
        {
            new Program().Run();
            Console.ReadLine();
        }

        private void Run()
        {
            int count = int.Parse(Console.ReadLine());

            var people = new List<Tuple<int, int>>(count);
            int totalWidth = 0;
            int maxHeight = 0;

            for (int i = 0; i < count; i++)
            {
                string nextLine = Console.ReadLine();

                int idx = nextLine.IndexOf(' ');
                int width = int.Parse(nextLine.Substring(0, idx));
                int height = int.Parse(nextLine.Substring(idx + 1, nextLine.Length - idx - 1));
                people.Add(new Tuple<int, int>(width, height));

                var current = people[i];
                totalWidth += current.Item1;
                maxHeight = current.Item2 > maxHeight ? current.Item2 : maxHeight;
            }

            var sortedPeople = people.OrderByDescending(x => x.Item2).ToList();
            var result = new List<int>(count);
            foreach (var photographer in people)
            {
                int max = maxHeight;
                if (photographer.Item2 == maxHeight)
                {
                    sortedPeople.Remove(photographer);
                    max = sortedPeople[0].Item2;
                }

                result.Add((totalWidth - photographer.Item1) * max);
            }

            Console.WriteLine(String.Join(" ", result));
        }
    }
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	int counter = 0;
	vector <pair<long long int, long long int>> p;
	for (int i = 0; i < n; i++) {
		long long int a, b;
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(p.begin(), p.end());
	for (int i = 1; i < n; i++) {
		for (int j = i-1; j > -1; j--) {
			if (p[j].second > p[i].second){
				counter++;
				break;
			}
		}
	}
	cout << counter;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cctype>
using namespace std;
#define res register int
#define ll long long
inline int read(){
	int s=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*f;
}
struct event{
	int b;
	int e;
};
int cmp(event a,event b){
	if(a.b!=b.b)return a.b<b.b;
	return a.e>b.e;
}
int main(){
	int n=read();
	event a[n];
	for(res i=0;i<n;++i){
		a[i].b=read();
		a[i].e=read();
	}
	sort(a,a+n,cmp);
	int maxv=0,tot=0;
	for(res i=0;i<n;++i){
		if(a[i].e<maxv)tot++;
		if(a[i].e>maxv)maxv=a[i].e;
	}
	printf("%d\n",tot);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxn = 2e4 + 10;  //分开const
const int maxm = 1e7 + 10;
const int inf = 0x3f3f3f3f;
int n, head[maxn], book[maxn], k, sum, dis[maxn];
struct node
{
    int v, w, pre;
    node(int vv, int ww) : v(vv), w(ww){}
    node() {}
    bool operator < (const node &a) const
    {
        return w > a.w;
    }
}edge[maxm];
void addedge(int u, int v, int w)
{
    edge[k].v = v;
    edge[k].w = w;
    edge[k].pre = head[u];
    head[u] = k++;
}
void prim(int u)
{
    for(int i = 1; i <= n; i++) dis[i] = inf;
    dis[u] = 0;
    priority_queue<node> pq;
    pq.push(node(u,dis[u]));
    while(!pq.empty())
    {
        u = pq.top().v;
        pq.pop();
        if(book[u]) continue;   //如果是1直接跳出，不加这个会超时
        book[u] = 1;
        sum += dis[u];
        for(int i = head[u]; i != -1; i = edge[i].pre)
        {
            int v = edge[i].v, w = edge[i].w;
            if(dis[v] > w && !book[v])
            {
                dis[v] = w;
                pq.push(node(v,dis[v]));
            }
        }
    }
}
int main()
{
    while(~scanf("%d",&n),n)
    {
        char str[maxn][8];
        memset(book,0,sizeof(book));
        memset(head,-1,sizeof(head));
        k = 1, sum = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%s",str[i]);
            for(int j = i; j >= 1; j--)
            {
                int ans = 0;
                for(int l = 0; l < 7; l++)
                {
                    if(str[i][l] != str[j][l])
                        ans++;
                }
                addedge(i,j,ans);
                addedge(j,i,ans);
            }
        }
        prim(1);
        printf("The highest possible quality is 1/%d.\n", sum);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ma=0,js=0;
	cin>>n;
	int m[n][2];
	for(int i=0;i<n;i++)
		for(int j=0;j<2;j++)
			cin>>m[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<2;j++)
		{
			js=0;
			for(int k=0;k<n;k++)
			{
				for(int l=0;l<2;l++)
				{
					if(m[0][j]<m[0][l]&&m[i][0]>m[k][0])
						js++;
				}
			}
			if(js>ma)
				ma=js;
		}
	}
	cout<<ma;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
bool comp(pair <int,int> p1,pair<int,int> p2)
{
	return p1.second<p2.second;
}
bool comp1(pair <int,int> p1,pair<int,int> p2)
{
	return p1.first>p2.first;
}
main()
{

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	pair <int,int> arr[n];
	pair <int,int> arr1[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i].first>>arr[i].second;
	}
	for(int i=0;i<n;i++)
	{
		arr1[i]=arr[i];
	}
	sort(arr1,arr1+n,comp1);
	sort(arr,arr+n,comp);
	int no=0;
	int maxs=-1;
	maxs=arr[0].first;
	int j=n-1;
	for(int i=0;i<n&&j>=0;i++)
	{
		if(arr1[i].first!=arr[j].first&&arr1[i].second!=arr[j].second)
		{
			no++;
		}
		else
		{
			j--;
		}
	}

	cout<<no;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
bool comp(pair <int,int> p1,pair<int,int> p2)
{
	return p1.second<p2.second;
}
bool comp1(pair <int,int> p1,pair<int,int> p2)
{
	return p1.first>p2.first;
}
main()
{

	int n;
	cin>>n;
    int uu=n;
	set <pair <int,int> >arr;
	vector< pair <int,int> > arr1;
	pair <int,int> arr2[n];  //jl
	for(int i=0;i<n;i++)
	{  int x,y;
		cin>>x>>y;
		arr.insert(make_pair(y,x));
		arr2[i].first=x;
		arr2[i].second=y;
	}
	for(int i=0;i<n;i++)
	{
		arr1.push_back(arr2[i]);
	}
	sort(arr1.begin(),arr1.end(),comp1);

	int no=0;
	int maxs=-1;
	//maxs=arr[0].first;
	int j=n-1;
	auto ls=arr.end();
	advance(ls,-1);
     //cout<<(*ls).first<<" "<<(*ls).second<<endl;
     n=uu;
	for(int i=0;i<n&&!arr.empty();i++)
	{

		if(arr1[i].first!=(*ls).second&&arr1[i].second!=(*ls).first)
		{
			no++;
		}
		else
		{

			auto it=arr.end();
            advance(it,-1);
			arr.erase(it);
            if(!arr.empty()){
            ls=arr.end();
            advance(ls,-1);}
			continue;
		}

         arr.erase(make_pair(arr1[i].second,arr1[i].first));
         if(!arr.empty()){
          ls=arr.end();
          advance(ls,-1);}
	}

	cout<<no;
	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
bool comp(pair <int,int> p1,pair<int,int> p2)
{
	return p1.second<p2.second;
}
bool comp1(pair <int,int> p1,pair<int,int> p2)
{
	return p1.first>p2.first;
}
main()
{

	int n;
	cin>>n;
    int uu=n;
	set <pair <int,int> >arr;
	vector< pair <int,int> > arr1;
	pair <int,int> arr2[n];
	for(int i=0;i<n;i++)
	{  int x,y;
		cin>>x>>y;
		arr.insert(make_pair(y,x));
		arr2[i].first=x;
		arr2[i].second=y;
	}
	for(int i=0;i<n;i++)
	{
		arr1.push_back(arr2[i]);
	}
	sort(arr1.begin(),arr1.end(),comp1);

	int no=0;
	int maxs=-1;
	//maxs=arr[0].first;
	int j=n-1;
	auto ls=arr.end();
	advance(ls,-1);
     //cout<<(*ls).first<<" "<<(*ls).second<<endl;
     n=uu;
	for(int i=0;i<n&&!arr.empty();i++)
	{

		if(arr1[i].first!=(*ls).second&&arr1[i].second!=(*ls).first)
		{
			no++;
		}
		else
		{

			auto it=arr.end();
            advance(it,-1);
			arr.erase(it);
            if(!arr.empty()){
            ls=arr.end();
            advance(ls,-1);}
			continue;
		}

         arr.erase(make_pair(arr1[i].second,arr1[i].first));
         if(!arr.empty()){
          ls=arr.end();
          advance(ls,-1);}
	}

	cout<<no;
	return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
bool u[int (1e5 + 100)];

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    sort (v.begin (), v.end ());

    for (int i=0; i<=v.size(); ++i) {
        if (u[i])
            continue;
        for (int j=v.size() - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
        }
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int INF = int (1e9);

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    sort (v.begin (), v.end ());

    int mx = -INF;
    for (int i=0; i<=v.size(); ++i) {
        if (mx > v[i].second)
            res++;
        else
            mx = v[i].second;
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int INF = int (1e9);

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    sort (v.begin (), v.end ());

    int mx = -INF;
    for (int i=0; i<v.size(); ++i) {
        if (mx > v[i].second)
            res++;
        else
            mx = v[i].second;
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;
bool u[int (1e5 + 100)];

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    for (int i=0; i<=v.size(); ++i) {
        if (u[i])
            continue;
        for (int j=int (v.size()) - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
            else
                break;
        }
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
bool u[int (1e5 + 100)];

inline bool cmp (pair <int, int> a, pair <int, int> b) {
    return a.first < b.first && a.second > b.second;
}

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    sort (v.begin (), v.end (), cmp);

    for (int i=0; i<=v.size(); ++i) {
        if (u[i])
            continue;
        for (int j=int (v.size()) - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
            else
                break;
        }
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
bool u[int (1e5 + 100)];

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    sort (v.begin (), v.end ());

    for (int i=0; i<=v.size(); ++i) {
        if (u[i])
            continue;
        for (int j=v.size() - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
            else
                break;
        }
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;
bool u[int (1e5 + 100)];

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    for (int i=0; i<=v.size(); ++i) {
        for (int j=v.size() - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
        }
    }

    printf ("%d\n", res);

    return 0;
}


//
//  main.cpp
//  Test
//
//  Created by Nurik Kozahmet on 20.03.16.
//  Copyright © 2016 Nurik Kozahmet. All rights reserved.
//

#include <iostream>
#include <vector>

using namespace std;
bool u[int (1e5 + 100)];

int main () {
    int n, res = 0;
    vector <pair <int, int> > v;

    scanf ("%d", &n);

    for (int i=1; i<=n; ++i) {
        int l, r;
        scanf ("%d%d", &l, &r);
        v.push_back (make_pair (l, r));
    }

    for (int i=0; i<=v.size(); ++i) {
        if (u[i])
            continue;
        for (int j=v.size() - 1; j>=0; --j) {
            int l1 = v[i].first, r1 = v[i].second, l2 = v[j].first, r2 = v[j].second;
            if (l1 < l2 && r2 < r1 && !u[j])
                u[j] = 1, res++;
        }
    }

    printf ("%d\n", res);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll            long long
#define pb            push_back
#define mp            make_pair
#define R             return 0
#define ff            first
#define ss            second
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define scl1(a)       scanf("%I64d",&a)
#define scl2(a,b)     scanf("%I64d %I64d",&a,&b)
#define all(a)        a.begin(),a.end()
#define REP(it,a,b)   for(ll it = a;it < b;it++)
#define FOR(IT,a,b)   for(ll IT = a;IT <= b;IT++)
#define pii           pair<int,int>
#define pll           pair<long,long>
#define hi            puts("Hi..!")
#define MAX           1000000
int fx[] = {1,-1,0,0};
int fy[] = {0,0,1,-1};
template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
struct Sorter{int FS,SC;}; // Define array here
bool cmp(Sorter A,Sorter B){if(A.FS==B.SC) return A.SC < B.SC;return A.FS < B.FS;}

int main() {
   int n;
   sc1(n);
   vector<pii> v;
    REP(i,0,n){
        int x,y;sc2(x,y);
       v.pb(mp(x,y));
    }
    sort(all(v));
    int cnt = 0;
    int mx = v[0].ss;
    REP(i,1,n){
        int keep = v[i].ss;
        if(mx > keep) cnt++;
        mx = max(mx,keep);
    }
    printf("%d\n",cnt);
   R;
}


#include <bits/stdc++.h>
using namespace std;
#define ll            long long
#define pb            push_back
#define mp            make_pair
#define R             return 0
#define ff            first
#define ss            second
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define scl1(a)       scanf("%I64d",&a)
#define scl2(a,b)     scanf("%I64d %I64d",&a,&b)
#define all(a)        a.begin(),a.end()
#define REP(it,a,b)   for(ll it = a;it < b;it++)
#define FOR(IT,a,b)   for(ll IT = a;IT <= b;IT++)
#define pii           pair<int,int>
#define pll           pair<long,long>
#define hi            puts("Hi..!")
#define MAX           1000000
int fx[] = {1,-1,0,0};
int fy[] = {0,0,1,-1};
template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
struct Sorter{int FS,SC;}; // Define array here
bool cmp(Sorter A,Sorter B){if(A.FS==B.SC) return A.SC < B.SC;return A.FS < B.FS;}

int main() {
   int n;
   sc1(n);
   vector<pii> v;
    REP(i,0,n){
        int x,y;sc2(x,y);
       v.pb(mp(x,y));
    }
    sort(all(v));
    int cnt = 0;
    int mx = v[0].ss;
    REP(i,1,n){
        int keep = v[i].ss;
        if(mx > keep) cnt++;
        mx = max(mx,keep);
    }
    cout << cnt << endl;
   R;
}


#include <bits/stdc++.h>
using namespace std;
#define ll            long long
#define pb            push_back
#define mp            make_pair
#define R             return 0
#define ff            first
#define ss            second
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define scl1(a)       scanf("%I64d",&a)
#define scl2(a,b)     scanf("%I64d %I64d",&a,&b)
#define all(a)        a.begin(),a.end()
#define REP(it,a,b)   for(ll it = a;it < b;it++)
#define FOR(IT,a,b)   for(ll IT = a;IT <= b;IT++)
#define pii           pair<int,int>
#define pll           pair<long,long>
#define hi            puts("Hi..!")
#define MAX           1000000
int fx[] = {1,-1,0,0};
int fy[] = {0,0,1,-1};
template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
struct Sorter{int FS,SC;}; // Define array here
bool cmp(Sorter A,Sorter B){if(A.FS==B.SC) return A.SC < B.SC;return A.FS < B.FS;}

int main() {
   int n;
   sc1(n);
   vector<pii> v;
    REP(i,0,n){
        int x,y;sc2(x,y);
       v.pb(mp(x,y));
    }
    sort(all(v));
    int cnt = 0;
    int pos,mx = 0;
    for(int i = 0;i < v.size();i++){
      if(v[i].ss > mx){
        pos = i;
        mx = v[i].ss;
      }
    }
    for(int i = n-1;i >= 1;i--){
      if(v[i].ss < mx && i > pos) cnt++;
    }
    cout << cnt << endl;
   R;
}


#include <bits/stdc++.h>
using namespace std;
#define ll            long long
#define pb            push_back
#define mp            make_pair
#define R             return 0
#define ff            first
#define ss            second
#define sc1(a)        scanf("%d",&a)
#define sc2(a,b)      scanf("%d%d",&a,&b)
#define scl1(a)       scanf("%I64d",&a)
#define scl2(a,b)     scanf("%I64d %I64d",&a,&b)
#define all(a)        a.begin(),a.end()
#define REP(it,a,b)   for(ll it = a;it < b;it++)
#define FOR(IT,a,b)   for(ll IT = a;IT <= b;IT++)
#define pii           pair<int,int>
#define pll           pair<long,long>
#define hi            puts("Hi..!")
#define MAX           1000000
int fx[] = {1,-1,0,0};
int fy[] = {0,0,1,-1};
template <class T> inline T bigmod(T p,T e,T M){
    ll ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
struct Sorter{int FS,SC;}; // Define array here
bool cmp(Sorter A,Sorter B){if(A.FS==B.SC) return A.SC < B.SC;return A.FS < B.FS;}

int main() {
   int n;
   sc1(n);
   vector<pii> v;
    REP(i,0,n){
        int x,y;sc2(x,y);
       v.pb(mp(x,y));
    }
    sort(all(v));
    int cnt = 0;
    for(int i = n-1;i >= 1;i--){
      int keep = v[i].ss;
      for(int j = i-1;j >= 0;j--){
        int match = v[j].ss;
        if(match > keep){
          cnt++;
          break;
        }
      }
    }
    cout << cnt << endl;
   R;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n,i,j,k;
pair <int,int> w[10000];

int main()
{
cin>>n;
for(i=0;i<n;i++)
{
  cin>>w[i].first;
  cin>>w[i].second;

}
  sort(w,w+n);
  for(i=1;i<n;i++)
  {

      for(j=i;j>0;j--)
      {
        if(w[j-1].second>w[i].second)
        {
          k++;
          break;
        }
      }

    }

 cout<<k;

}


#include <iostream>
#include <algorithm>
using namespace std;
int a,n,b,i,j,x,k,y,d;
pair <int,int> w[100000];

int main()
{
cin>>n;
for(i=0;i<n;i++)
{
  cin>>w[i].first;
  cin>>w[i].second;

}
  sort(w,w+n);
  for(i=1;i<n;i++)
  {

      for(j=i;j>0;j--)
      {
        if(w[j-1].second>w[i].second)
        {
          k++;
          break;
        }
      }

    }

 cout<<k;

}


#include <iostream>
#include <algorithm>
using namespace std;
int n,i,j,k,m;
pair <int,int> w[100000];

int main()
{
cin>>n;
for(i=0;i<n;i++)
{
  cin>>w[i].first;
  cin>>w[i].second;

}
  sort(w,w+n);
  m=w[0].second;
  for(i=1;i<n;i++)
  {

        if(m>w[i].second)
        {
          k++;

        }
        else
        {
          m=w[i].second;
        }
      }
      cout<<k;
    }


#include <iostream>
#include <algorithm>
using namespace std;
int a,n,b,i,j,x,k,y,d;
pair <int,int> w[100000];

int main()
{
cin>>n;
for(i=0;i<n;i++)
{
  cin>>w[i].first;
  cin>>w[i].second;

}
  sort(w,w+n);
  for(i=1;i<n;i++)
  {

      for(j=i;j>=0;j--)
      {
        if(w[j-1].second>w[j].second)
        {
          k++;
          break;
        }
      }

    }

 cout<<k;

}


#include <iostream>
#include <algorithm>
using namespace std;
int n,i,j,k;
pair <int,int> w[100000];

int main()
{
cin>>n;
for(i=0;i<n;i++)
{
  cin>>w[i].first;
  cin>>w[i].second;

}
  sort(w,w+n);
  for(i=1;i<n;i++)
  {

      for(j=i;j>0;j--)
      {
        if(w[j-1].second>w[i].second)
        {
          k++;
          break;
        }
      }

    }

 cout<<k;

}


#include <bits/stdc++.h>

using namespace std;

int bs(int s, int e, pair<int, int> x[], pair<int, int> key, int i) {
	while (s <= e) {

		int mid = (s + e) / 2;
		//if (i == 3)
			//cout << mid << " " << key.first << " " << x[mid].first << " "
				//	<< x[mid].second << endl;
		if (key.first > x[mid].first && key.second < x[mid].second) {
			return mid;
		} else if (x[mid].first >= key.first)
			e = mid - 1;
		else if (x[mid].second <= key.second) {
			int s = 0;
			s = bs(mid + 1, e, x, key, i);
			if (s == -1)
				s = bs(s, mid - 1, x, key, i);
			return s;
		}

	}
	return -1;
}

int main() {
	int n;
	cin >> n;
	pair<int, int> x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
	}
	sort(x, x + n);
	int c = 0;
	for (int i = 0; i < n; i++) {
		//cout << x[i].first << " " << x[i].second << endl;
		if (bs(0, n - 1, x, x[i], i) != -1)
			c++;

	}
	cout << c << endl;

}


#include <bits/stdc++.h>

using namespace std;

int bs(int s, int e, pair<int, int> x[], pair<int, int> key, int i) {
	int sa = - 1;
	while (s <= e) {

		int mid = (s + e) / 2;
		//if (i == 3)
			//cout << mid << " " << key.first << " " << x[mid].first << " "
				//	<< x[mid].second << endl;
		if (key.first > x[mid].first && key.second < x[mid].second) {
			return mid;
		} else if (x[mid].first >= key.first)
			e = mid - 1;
		else if (x[mid].second <= key.second) {
			sa = bs(mid + 1, e, x, key, i);
			if (s == -1)
				sa = bs(s, mid - 1, x, key, i);
		}

	}
	return sa;
}

int main() {
	int n;
	cin >> n;
	pair<int, int> x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
	}
	sort(x, x + n);
	int c = 0;
	for (int i = 0; i < n; i++) {
		//cout << x[i].first << " " << x[i].second << endl;
		if (bs(0, n - 1, x, x[i], i) != -1)
			c++;

	}
	cout << c << endl;

}


#include <bits/stdc++.h>

using namespace std;

int main() {

	int n;
	cin >> n;
	pair<int, int> x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
	}
	sort(x, x + n);
	int max = x[0].second;
	int c = 0;
	for (int i = 1; i < n; i++) {
		if (max > x[i].second)
			c++;
		else
			max = x[i].second;
	}
	cout << c << endl;

}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	pair<int, int> x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
	}
	sort(x, x + n);
	int c = 0;
	for (int i = 0; i < n - 1; i++) {
		if (x[i].first > x[i + 1].first && x[i].second < x[i + 1].second) {
			c++;
		}
	}
	cout << c << endl;
}


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

int main(){
	int a,total=0;
	cin>>a;
int tirta[a],tirta2[a];
	for(int i=0; i<a; i++){
		cin >> tirta[i] >> tirta2[i];
	}
	sort(tirta,tirta+a);

	int max = tirta2[0];
	for(int t=1;t<a;t++){
		if(tirta2[t] < max){
			total++;
		}else
		{
			max=tirta2[t];
		}
	}
	cout<<total<<endl;

	return 0;
}


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

int main(){
	int a,total=0;
	cin>>a;
	pair<int,int> tirta[a];
	for(int i=0; i<a; i++){
		cin >> tirta[i].first >> tirta[i].second;
	}
	sort(tirta,tirta+a);

	int max = tirta[0].second;
	for(int t=1;t<a;t++){
		if(tirta[t].second<max){
			total++;
		}else{
			max=tirta[t].second;
		}
	}
	cout<<total<<endl;

	return 0;
}


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

int main(){
	int a,total=0;
	cin>>a;
int tirta[a],tirta2[a];
	for(int i=0; i<a; i++){
		cin >> tirta[i] >> tirta2[i];
	}
	sort(tirta,tirta+a);

	int max = tirta2[0];
	for(int t=0;t<a;t++){
		if(tirta2[t] < max){
			total++;
		}else
		{
			max=tirta2[t];
		}
	}
	cout<<total<<endl;

	return 0;
}


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

int main(){
	int a,total=0;
	cin>>a;
int tirta[a],tirta2[a];
	for(int i=0; i<a; i++){
		cin >> tirta[i] >> tirta2[i];
	}
	sort(tirta,tirta+a);

	int max = tirta2[0];
	for(int t=0;t<=a;t++){
		if(tirta2[t] < max){
			total++;
		}else
		{
			max=tirta2[t];
		}
	}
	cout<<total<<endl;

	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
/*
#include <sstream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include<climits>
#include <bitset>
#include <ctime>
#include <cassert>
#include <functional>
#include <iomanip>
#include <vector>
#include <stack>
*/
//#include <fstream>
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//cout<<fixed<<setprecision(*)<<***<<endl;

/*
scanf("%d %d" , &.. , &..) ;
printf("%d" , ..);
*/
using namespace std;

vector<pair<long long,long long> >vec;
int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);*/

    int n,maxi=0,c=0; scanf("%d",&n);
    vec.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&vec[i].first,&vec[i].second);
    }
    if(n==1){return printf("%d",0),0;}
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if((vec[j].first>vec[i].first)&&(vec[j].second<vec[i].second)){c++;}
        }
        if(c>maxi){maxi=c; c=0; continue;}
        else
        {
            if(c==maxi){maxi=maxi+c; c=0; continue;}
            else{c=0; continue;}
        }
    }
    printf("%d",maxi);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
/*
#include <sstream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include<climits>
#include <bitset>
#include <ctime>
#include <cassert>
#include <functional>
#include <iomanip>
#include <vector>
#include <stack>
*/
//#include <fstream>
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//cout<<fixed<<setprecision(*)<<***<<endl;

/*
scanf("%d %d" , &.. , &..) ;
printf("%d" , ..);
*/
using namespace std;

vector<pair<long long,long long> >vec;
int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);*/

    int n,maxi=0,c=0; scanf("%d",&n);
    vec.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&vec[i].first,&vec[i].second);
    }
    if(n==1){return printf("%d",0),0;}
    sort(vec.begin(),vec.end());
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if((vec[j].first>vec[i].first)&&(vec[j].second<vec[i].second)){c++;}
        }
        if(c>maxi){maxi=c; c=0; continue;}
        else{c=0; continue;}
    }
    printf("%d",maxi);

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
/*
#include <sstream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include<climits>
#include <bitset>
#include <ctime>
#include <cassert>
#include <functional>
#include <iomanip>
#include <vector>
#include <stack>
*/
//#include <fstream>
//std::ifstream cin("input.txt");
//std::ofstream cout("output.txt");
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//cout<<fixed<<setprecision(*)<<***<<endl;

/*
scanf("%d %d" , &.. , &..) ;
printf("%d" , ..);
*/
using namespace std;

vector<pair<long long,long long> >vec;
int main()
{
    /*ios_base::sync_with_stdio(0);
    cin.tie(0);*/

    int n,c=0; scanf("%d",&n);
    vec.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&vec[i].first,&vec[i].second);
    }
    if(n==1){return printf("%d",0),0;}
    sort(vec.begin(),vec.end());
    for(int i=0;i==0;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if (vec[j].second<vec[i].second){c++;}
            else{vec[i].second=vec[j].second;}
    	}
    }
    printf("%d",c);

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stdlib.h>
#include <ctime>
using namespace std;
#define forr(n) for(ll i=0;i<n;i++)
#define forrr(n) for(unsigned long long i=1;i<n;i++)
#define forb(n) for(long long i=n-1;i>=0;i--)
#define PI (double)3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector< ll > llvector;
typedef vector<string> svector;
typedef vector< pair<ll,ll> > pairsvector; //pairs.push_back(make_pair(temp1,temp2)); scanf("%ld %ld\n", &data[p].first, &data[p].second);
typedef vector< pair< pair<ll,ll> , bool > > pairsboolvector;
typedef set<int> yset;
typedef map<ll,char> ymap;
typedef priority_queue<ll> ypq;
typedef pair<ll,ll> ypair;
typedef bitset<32>  ybitset;
void                      printvictor(vector<ll> v){forr(v.size())cout<<v[i]<<" ";cout<<endl;}
void                      printPQ(priority_queue<ll> pq){while (!pq.empty()){cout<<pq.top()<<" ";pq.pop();}std::cout << '\n';}
template <class T> string toStr(const T &x){ stringstream s; s << x; return s.str(); }
template <class T> ll     toInt(const T &x){ stringstream s; s << x; ll r; s >> r; return r; }
bool                      isprime(ll n) {if(n == 2)  return true;if(n < 2 || n%2 == 0)   return false;for(ll i=3; i*i <= n; i+=2){if(n%i == 0)return false;}return true;}
vector<ll>                generate_divisors(ll n){vector<ll> v;ll i;for(i = 1 ; i <=  n  ;++i)if(n%i == 0)v.push_back(i);return v;}
ll 		BinaryToDec(string binary){ll arr[binary.length()];ll sum=0;forr(binary.length())arr[i] = pow(2,i);reverse(binary.begin(),binary.end());forr(binary.length())if(toInt(binary[i]) == 1)sum+=arr[i];return sum;}
string  DecToBinary(ll decimal){string binary = "";while(true){if(decimal %2 ==0)binary += '0';else binary += '1';if(decimal==1)break;decimal /= 2;}reverse(binary.begin(),binary.end());return binary;}
ll     gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);}
//--------------------------------------------------------------------YASSER ALAA ELDIN--------------------------------------------------------------------------
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r", stdin);
    freopen("out.txt","w", stdout);
    #endif
   	int n;
   	cin>>n;
   	std::vector< pair<ll,ll> > yvec;
   		ll temp1,temp2;
   	forr(n)
   	{
   		cin>>temp1>>temp2;
   		yvec.push_back(make_pair(temp1,temp2));
   	}
   	int counter=0;
   	for(int i =0;i<yvec.size();i++)
   	{
   		for(int j=i+1;j<yvec.size();j++)
   			if(yvec[j].first>yvec[i].first && yvec[j].second<yvec[i].second)
   			{
   				counter++;
   				yvec.erase(yvec.begin()+j);
   				j--;
   				//break;
   			}
   	}

   		cout<<counter<<"\n";

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <sstream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stdlib.h>
#include <ctime>
#include <stack>
using namespace std;
#define forr(n) for(ll i=0;i<n;i++)
#define forrr(n) for(unsigned long long i=1;i<n;i++)
#define forb(n) for(long long i=n-1;i>=0;i--)
#define PI (double)3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector< ll > llvector;
typedef vector<string> svector;
typedef vector< pair<ll,ll> > pairsvector; //pairs.push_back(make_pair(temp1,temp2)); scanf("%ld %ld\n", &data[p].first, &data[p].second);
typedef vector< pair< pair<ll,ll> , bool > > pairsboolvector;
typedef set<int> yset;
typedef map<ll,char> ymap;
typedef priority_queue<ll> ypq;
typedef pair<ll,ll> ypair;
typedef bitset<32>  ybitset;
void                      printvictor(vector<ll> v){forr(v.size())cout<<v[i]<<" ";cout<<endl;}
void                      printPQ(priority_queue<ll> pq){while (!pq.empty()){cout<<pq.top()<<" ";pq.pop();}std::cout << '\n';}
template <class T> string toStr(const T &x){ stringstream s; s << x; return s.str(); }
template <class T> ll     toInt(const T &x){ stringstream s; s << x; ll r; s >> r; return r; }
bool                      isprime(ll n) {if(n == 2)  return true;if(n < 2 || n%2 == 0)   return false;for(ll i=3; i*i <= n; i+=2){if(n%i == 0)return

false;}return true;}
vector<ll>                generate_divisors(ll n){vector<ll> v;ll i;for(i = 1 ; i <=  n  ;++i)if(n%i == 0)v.push_back(i);return v;}
ll 		BinaryToDec(string binary){ll arr[binary.length()];ll sum=0;forr(binary.length())arr[i] = pow(2,i);reverse(binary.begin(),binary.end

());forr(binary.length())if(toInt(binary[i]) == 1)sum+=arr[i];return sum;}
string  DecToBinary(ll decimal){string binary = "";while(true){if(decimal %2 ==0)binary += '0';else binary += '1';if(decimal==1)break;decimal /= 2;}

reverse(binary.begin(),binary.end());return binary;}
ll     gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);}
//--------------------------------------------------------------------YASSER ALAA ELDIN--------------------------------------------------------------------------

int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r", stdin);
    freopen("out.txt","w", stdout);
    #endif
	int n,temp1,temp2;
	cin>>n;
	std::vector< pair<ll,ll> > yvector(n);
	forr(n)
	{
	cin>>temp1>>temp2;
	yvector[i]=make_pair(temp1,temp2);
	}
	sort(yvector.begin(),yvector.end());
	int counter=0;
	temp1=yvector[0].first;temp2=yvector[0].second;
	forrr(n)
	{
		if(temp1<yvector[i].first&&temp2>yvector[i].second)
			counter++;
   	   else
         temp1=yvector[i].first,temp2=yvector[i].second;
	}
	cout<<counter<<"\n";
    return 0;
}


#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<iterator>
using namespace std;

#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)
#define max(a,b) (((a > b)) ? (a) : (b))
#define min(a,b) (((a < b)) ? (a) : (b))

typedef long long         ll;
const ll OO = 1e8;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

#define pb                  push_back
#define MP                  make_pair
#define P(x)                cout<<#x<<" = { "<<x<<" }\n"
typedef long double       ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

class UnionFind {

private: vi p,rank;
public:
	UnionFind(int N) {
		rank.assign(N, 0); p.assign(N, 0);
		for (size_t i = 0; i < N; i++)
			p[i] = i;
	}
	int findSet(int i) {
		return (p[i] == i) ? i : (p[i] = findSet(p[i]));
	}
	bool isSameSet(int i, int j) {
		return findSet(i) == findSet(j);
	}
	void unionSet(int i, int j)
	{
		if (!isSameSet(i, j)) {
			int x = findSet(i), y = findSet(j);
			if (rank[x] > rank[y])p[y] = x;
			else
			{
				p[x] = y;
				if (rank[x] == rank[y])rank[y]++;
			}
		}
	}
};
int numberOfDigits(int x)
{
	return log10(x) + 1;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input_here.txt", "rt", stdin);
	/*freopen("output_here.txt", "wt", stdout);*/
#endif
	ll in,x,a,b;
	cin >> in;
	multimap<ll,ll> vee;
	for (size_t i = 0; i < in; i++)
	{
		cin >> a >> b;
		vee.insert(make_pair(a, b));
	}
	multimap<ll, ll>::iterator it = vee.begin();
	multimap<ll, ll>::iterator itt = vee.begin();
	bool find = false;
	int c(0);
	for (; it != vee.end(); it++)
	{
		for (; itt != vee.end(); itt++)
		{
			if (itt->first > it->first && it->second > itt->second) { c++; }
		}
	}

		cout << c << endl;
		/*for (size_t a = 0; a < x - 5; a++)
			for (size_t b = a + 1; b < x - 4; b++)
				for (size_t c = b + 1; c < x - 3; c++)
					for (size_t d = c + 1; d < x - 2; d++)
						for (size_t e = d + 1; e < x - 1; e++)
							for (size_t f = e + 1; f < x; f++)
								cout << p[a] << " " << p[b] << " " << p[c] << " " << p[d] << " " << p[e] << " " << p[f] << endl;*/
	//int tc,count;
	//
	//scanf("%d", &tc);
	//while (tc--)
	//{
	//	count = 0;
	//	scanf("%d %d", &n,&m);
	//	map<int, int> mp;
	//	for (size_t i = 0; i < n; i++)
	//		for (size_t j = 0; j < m; j++)
	//			scanf("%d", &acm[i][j]);
	//
	//
	//
	//	for (size_t i = 0; i < n; i++)
	//		for (size_t j = 0; j < m; j++)
	//			if(acm[i][j] != -1)
	//			if (hasAdjiacent(i, j))mp[acm[i][j]]++;
	//	/*cout << "---- Matrix ---- " << endl;
	//	for (size_t i = 0; i < n; i++)
	//	{
	//		for (size_t j = 0; j < m; j++)
	//		{
	//			cout << acm[i][j] << " ";
	//		}
	//		cout << endl;
	//	}*/
	//	map<int, int>::iterator it;
	//	for (it = mp.begin(); it != mp.end(); it++)
	//	{
	//		if ((it->second) > 2)count++;
	//		/*printf("--Team %d --Adj %d -- %d --\n", it->first, it->second, count);*/
	//	}
	//
	//
	//	printf("%d\n", count);

	//}

	/*int tc,ascii,trees,acron,total;
	cin >> tc;
	string s;
	while (tc--)
	{
		UnionFind uf(27);
		uf.unionSet(26, 26);

		trees = acron = total = 0;
		while (cin >> s && s[0] == '(')
			uf.unionSet((int)s[1]-65, (int)s[3]-65);
		cin >> s;
		int repeat[26][26];
		multimap<int, int> totals;
		memset(repeat, 0, sizeof(repeat));
		for (size_t i = 0; i < s.size(); i+=2)
		{
			for (size_t j = 0; j < s.size(); j+=2)
			{
				if (uf.isSameSet((int)s[i] - 65, (int)s[j] - 65))
				{
					repeat[i][j] = uf.findSet((int)s[i] - 65);
				}
			}
		}
		total = s.size() / 2;
		for (size_t i = 0; i < total; i++)
		{
			if (repeat[i]>1)trees++;
		}
		acron = total - trees;
		printf("There are %d tree(s) and %d acorn(s).\n", trees, acron);
	}
*/

#ifndef ONLINE_JUDGE
	cout << "\n\n\n" << fixed << "TIME: " << clock() / (CLOCKS_PER_SEC*1.0) << " s" << endl;
#endif

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <sstream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stdlib.h>
#include <ctime>
#include <stack>
using namespace std;
#define forr(n) for(ll i=0;i<n;i++)
#define forrr(n) for(unsigned long long i=1;i<n;i++)
#define forb(n) for(long long i=n-1;i>=0;i--)
#define PI (double)3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862
#define MOD 1000000007
typedef long long int ll;
typedef long double ld;
typedef vector< ll > llvector;
typedef vector<string> svector;
typedef vector< pair<ll,ll> > pairsvector; //pairs.push_back(make_pair(temp1,temp2)); scanf("%ld %ld\n", &data[p].first, &data[p].second);
typedef vector< pair< pair<ll,ll> , bool > > pairsboolvector;
typedef set<int> yset;
typedef map<ll,char> ymap;
typedef priority_queue<ll> ypq;
typedef pair<ll,ll> ypair;
typedef bitset<32>  ybitset;
void                      printvictor(vector<ll> v){forr(v.size())cout<<v[i]<<" ";cout<<endl;}
void                      printPQ(priority_queue<ll> pq){while (!pq.empty()){cout<<pq.top()<<" ";pq.pop();}std::cout << '\n';}
template <class T> string toStr(const T &x){ stringstream s; s << x; return s.str(); }
template <class T> ll     toInt(const T &x){ stringstream s; s << x; ll r; s >> r; return r; }
bool                      isprime(ll n) {if(n == 2)  return true;if(n < 2 || n%2 == 0)   return false;for(ll i=3; i*i <= n; i+=2){if(n%i == 0)return

false;}return true;}
vector<ll>                generate_divisors(ll n){vector<ll> v;ll i;for(i = 1 ; i <=  n  ;++i)if(n%i == 0)v.push_back(i);return v;}
ll 		BinaryToDec(string binary){ll arr[binary.length()];ll sum=0;forr(binary.length())arr[i] = pow(2,i);reverse(binary.begin(),binary.end

());forr(binary.length())if(toInt(binary[i]) == 1)sum+=arr[i];return sum;}
string  DecToBinary(ll decimal){string binary = "";while(true){if(decimal %2 ==0)binary += '0';else binary += '1';if(decimal==1)break;decimal /= 2;}

reverse(binary.begin(),binary.end());return binary;}
ll     gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a%b);}
//--------------------------------------------------------------------YASSER ALAA ELDIN--------------------------------------------------------------------------

int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r", stdin);
    freopen("out.txt","w", stdout);
    #endif
	int n,temp1,temp2;
	cin>>n;
	std::vector< pair<ll,ll> > yvector(n);
	forr(n)
	{
	cin>>temp1>>temp2;
	yvector[i]=make_pair(temp1,temp2);
	}
	sort(yvector.begin(),yvector.end());
	int counter=0;
	forrr(n)
	{
		if(yvector[i-1].first<=yvector[i].first&&yvector[i-1].second>yvector[i].second)
			counter++;
	}
	cout<<counter<<"\n";
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((l+r)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long
using ul = unsigned long long;
//using PII = pair<int, int>;
const int NN = (1000000009);
long long sum[NN];
int m,n;
int a,b,c;
pair<int,int>gg[100005];

int cmp(const pair<int,int>a,const pair<int,int>b){
    return a.first<b.first&&a.second>b.second;
}
int main() {
    scanf("%d",&n);
    for (int i = 0; i <n; ++i) {
        scanf("%d %d",&gg[i].first,&gg[i].second);
        int x = gg[i].first;
        int y = gg[i].second;
        sum[x+1]+=1;
        sum[y+1]-=1;
    }
    for(int i=1;i<NN;i++){
        sum[i]+=sum[i-1];
    }
    for(int i=0;i<n;i++){
        if(sum[gg[i].first+1]>0&&sum[gg[i].second]>0){
            a++;
        }
    }
    if(a==0){
        cout<<0;exit;
    }
    cout<<a-1;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((l+r)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long
using ul = unsigned long long;
//using PII = pair<int, int>;
const int NN = (10000009);
long long sum[NN];
int m,n;
int a,b,c;
pair<long long,long long >gg[100005];

int main() {
    scanf("%d",&n);
    for (int i = 0; i <n; ++i) {
        cin>>gg[i].first>>gg[i].second;
    }
    sort(gg,gg+n);
    long long x = gg[0].second;
    for(int i=1;i<n;i++){
        if(x>gg[i].second){
            a++;
            x= gg[i].second;
        }
    }
    if(a==0){
        cout<<0;exit;
    }
    cout<<a;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((l+r)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long
using ul = unsigned long long;
//using PII = pair<int, int>;
const int NN = (10000009);
long long sum[NN];
int m,n;
int a,b,c;
pair<long long,long long >gg[100005];

int main() {
    scanf("%d",&n);
    for (int i = 0; i <n; ++i) {
        cin>>gg[i].first>>gg[i].second;
    }
    sort(gg,gg+n);
    long long x = gg[0].second;
    for(int i=1;i<n;i++){
        if(x>gg[i].second){
            a++;
        } else x= gg[i].second;
    }
    if(a==0){
        cout<<0;exit;
    }
    cout<<a;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((l+r)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long
using ul = unsigned long long;
//using PII = pair<int, int>;
const int NN = (10000009);
long long sum[NN];
int m,n;
int a,b,c;
pair<long long,long long >gg[100005];

int main() {
    scanf("%d",&n);
    for (int i = 0; i <n; ++i) {
        cin>>gg[i].first>>gg[i].second;
    }
    sort(gg,gg+n);
    long long x = gg[0].second;
    for(int i=1;i<n;i++){
        if(x>gg[i].second){
            a++;
            x= gg[i].first;
        }
    }
    if(a==0){
        cout<<0;exit;
    }
    cout<<a;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <stack>
#include <cassert>
#include <fstream>
#include <cstring>
#include <numeric>
#include <ctype.h>
#include <stdio.h>
#define MOD 1000000007
#define exit return 0
#define inf 10000000000
#define exit return 0
#define PS system("pause")
#define mx(a,b) a>b?a:b
#define R0(i,n) for (i = 0; i < n; i++)
#define R1(i,n) for (i = 1; i <= n; i++)
#define MS(a,x) memset(x, a, sizeof(x));
#define left (v<<1)
#define right (left|1)
#define mid ((l+r)>>1)
#define SZ(x) ((int)x.size())
#define MX(a,b)a>b?a:b
const double eps = 1e-10;
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
#define ll long long
using ul = unsigned long long;
//using PII = pair<int, int>;
const int NN = (10000009);
long long sum[NN];
int m,n;
int a,b,c;
pair<long long,long long >gg[100005];

int main() {
    scanf("%d",&n);
    for (int i = 0; i <n; ++i) {
        cin>>gg[i].first>>gg[i].second;
    }
    sort(gg,gg+n);
    int x = gg[0].first;
    for(int i=1;i<n;i++){
        if(x<gg[i].first){
            a++;
            x= gg[i].first;
        }
    }
    if(a==0){
        cout<<0;exit;
    }
    cout<<a;
    return 0;

}