#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn keta(n: usize) -> usize {
    let mut n = n;
    let mut count = 0;
    while n > 0 {
        count += 1;
        n /= 10;
    }
    count
}

fn lower_bound<F>(l: usize, r: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    l
}

fn solve() {
    let n = get!(usize);
    let mut sum = 0;
    let nketa = keta(n);

    if nketa == 1 {
        println!("{}", n);
        return;
    } else if nketa == 2 {
        for a in 1..n+1 {
            let bottom = a % 10;
            let top = if a > 9 {
                a/10usize.pow(keta(a) as u32-1) % 10
            } else {
                a
            };
            if top == 0 || bottom == 0 {
                continue;
            }
            if top == bottom {
                sum += 1;
            }
            let res = bottom*10+top;
            if res <= n {
                sum += 1;
            }
        }
        println!("{}", sum);
        return;
    }

    for a in 1..n+1 {
        let bottom = a % 10;
        let top = if a > 9 {
            a/10usize.pow(keta(a) as u32-1) % 10
        } else {
            a
        };
        if top == 0 || bottom == 0 {
            continue;
        }
        if top == bottom {
            sum += 1;
        }
        for k in (nketa-1..nketa+1).rev() {
            let crit = |t: usize| {
                let val = bottom * 10usize.pow(k as u32-1) + t*10 + top;
                val > n
            };
            let t = lower_bound(0, 10usize.pow(k as u32-2), crit);
            let mx = bottom*10usize.pow(k as u32-1) + 10*t + top;
            if mx > n {
                continue;
            }
            let mk = keta(mx);
            if mk == 2 {
                sum += 1;
            } else {
                for i in 0..mk-2 {
                    sum += 10usize.pow(i as u32);
                }
                sum += t+1;
            }
            break;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 8572